Search code examples
pythonrecursionstructurethrift

Python: Recursive Structs


I have problem with thrift code generator or python.

Code sample (generated by thrift):

class SomeClass:
    spec = (
            (1, (SomeClass, SomeClass.spec)),
    )

Error message:

NameError: name 'SomeClass' is not defined

So I found bug in thrift jira (still opened since 2014). Suggested solution pretty bad.

Can I avoid this problem somehow?

In best case solution in *.thrift or *.py files, that can be changed before or after generation manually.


Solution

  • Seems, thats python's genered code contains useless field

    SomeClass.spec
    

    So i just delete it.

    I compared this with java generated code.

    If someone will use my solution dont forget to change generated methods, thats check, when your spec!=None