neogeny / TatSu

竜 TatSu generates Python parsers from grammars in a variation of EBNF

Home Page:https://tatsu.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tatsu.ast.AST objects don't pickle/unpickle properly

fizbin opened this issue · comments

Observe:

>>> from tatsu.ast import AST
>>> a=AST(parseinfo=('Some parseinfo'))
>>> a
{'parseinfo': 'Some parseinfo'}
>>> import pickle
>>> pickle.loads(pickle.dumps(a))
{'parseinfo_': 'Some parseinfo'}

Note that after pickling/unpickling, the AST object is different.

I believe that this can be fixed by changing __reduce__ to:

    def __reduce__(self):
        return (AST, (list(self.items()),))

Thanks, @fizbin!

Have you tested the proposed change?

Could you post it as a pull request?