Consensys / python-solidity-parser

An experimental Solidity parser for Python built on top of a robust ANTLR4 grammar 📚
https://pypi.org/project/solidity-parser/
142 stars 37 forks source link

Parsing the acquired object is not serializable #26

Closed litcc closed 2 years ago

litcc commented 2 years ago

This code does not execute and cannot serialize the variable kk2, making it impossible to transfer this data between multiple python processes


from solidity_parser import parse_file,objectify
import pickle

if __name__ == "__main__":
    print("Hello World!")
    kk = parse_file(path="samples/simple.sol")
    kk2 = objectify(kk)
    k3 = pickle.dumps(kk2)
    print(k3)
benharbit commented 11 months ago

How do you solve this problem?

litcc commented 11 months ago

Oh, and this is a bit old, I forget exactly, it's possible that parse_file(path) is being used instead of parse(text)

benharbit commented 11 months ago

it turns out you can use the multiprocessing library in python 3.11 and not 3.9 because 3.11 defines setstate and getstate. If you are are using a python version less than 3.11 you can just add setstate and getstate to the parser Class Node