[ https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075531#comment-16075531 ]
ASF GitHub Bot commented on THRIFT-2642: ---------------------------------------- Github user juliengreard commented on a diff in the pull request: https://github.com/apache/thrift/pull/1293#discussion_r125757042 --- Diff: compiler/cpp/src/thrift/generate/t_py_generator.cc --- @@ -610,11 +623,22 @@ string t_py_generator::render_const_value(t_type* type, t_const_value* value) { return out.str(); } +/** + * Generates the "forward declarations" for python structs. + * These are actually full class definitions so that calls to generate_struct + * can add the thrift_spec field. This is needed so that all thrift_spec + * definitions are grouped at the end of the file to enable co-recursive structs. + */ +void t_py_generator::generate_forward_declaration(t_struct* tstruct) { + generate_py_struct(tstruct, tstruct->is_xception()); +} + /** * Generates a python struct */ void t_py_generator::generate_struct(t_struct* tstruct) { - generate_py_struct(tstruct, false); + //generate_py_struct(tstruct, false); --- End diff -- bad idea to leave commented code - if you really want to leave it there, leave also a comment explaining why > Recursive structs don't work in python > -------------------------------------- > > Key: THRIFT-2642 > URL: https://issues.apache.org/jira/browse/THRIFT-2642 > Project: Thrift > Issue Type: Bug > Components: Python - Compiler, Python - Library > Affects Versions: 0.9.2 > Reporter: Igor Kostenko > Assignee: Eric Conner > > Recursive structs in 0.9.2 work fine in c++ & c#, but not in python, because > generated code trying to use objects which not constructed yet. > Struct: > {code} > struct Recursive { > 1: list<Recursive> Children > } > {code} > Python code: > {code} > class Recursive: > thrift_spec = ( > None, # 0 > (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive, > Recursive.thrift_spec)), None, ), # 1 > ) > {code} > Error message: > {code} > Traceback (most recent call last): > File "ttypes.py", line 20, in <module> > class Recursive: > File "ttypes.py", line 28, in Recursive > (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive, > Recursive.thrift_spec)), None, ), # 1 > NameError: name 'Recursive' is not defined > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)