[
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14539620#comment-14539620
]
julien greard edited comment on THRIFT-2642 at 5/12/15 10:14 AM:
-----------------------------------------------------------------
I did my own work around:
in the example above, I replaced the code:
class Recursive:
thrift_spec = (
None, # 0
(1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
Recursive.thrift_spec)), None, ), # 1
)
by
class Recursive:
pass
Recursive.thrift_spec = None
depth = 0
max_depth = 50
while (depth < max_depth):
depth += 1
Recursive. thrift_spec = (
None, # 0
(1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
Recursive.thrift_spec)), None, ), # 1
)
Which seems to do the job... It's ugly because I have to edit the generated
code afterward, but I didn't want to touch at the code generator in Thrift
code... what do you think ?
was (Author: juliengreard):
I did my own work around:
in the example above, I replaced the code:
class Recursive:
thrift_spec = (
None, # 0
(1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
Recursive.thrift_spec)), None, ), # 1
)
by
class Recursive:
pass
Recursive.thrift_spec = None
depth = 0
max_depth = 50
while (depth < max_depth):
depth += 1
Recursive. thrift_spec = (
None, # 0
(1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
Recursive.thrift_spec)), None, ), # 1
)
Which seems to do the job... It's ugly because I have to edit the generated
code afterward, but I didn't want to touch at the code generator in Thrift
code... what do you think ?
> 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
>
> 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:
> {quote}struct Recursive {
> 1: list<Recursive> Children
> }
> {quote}
> Python code:
> {quote}class Recursive:
> thrift_spec = (
> None, # 0
> (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
> Recursive.thrift_spec)), None, ), # 1
> )
> {quote}
> An error:
> {quote}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
> {quote}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)