[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075530#comment-16075530
 ] 

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_r125759228
  
    --- Diff: lib/py/src/TRecursive.py ---
    @@ -0,0 +1,63 @@
    +# MODIFIED June 20, 2017, Eric Conner
    +#
    +#
    +# Original source copyright 2014-present Facebook, Inc.
    +#
    +#
    +# Licensed under the Apache License, Version 2.0 (the "License");
    +# you may not use this file except in compliance with the License.
    +# You may obtain a copy of the License at
    +#
    +#   http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +from __future__ import absolute_import
    +from __future__ import division
    +from __future__ import print_function
    +from __future__ import unicode_literals
    +
    +from thrift.Thrift import TType
    +
    +
    +def fix_spec(all_structs):
    --- End diff --
    
    Well I'm sorry but I dont understand this file. Maybe explaining what the 
functions are doing would help. You could also use named variables instead of 
using directly 'magic' numbers (like const static int name = 1). But I may be 
wrong, I'm a complete stranger to the source code of thrift, so maybe it's the 
way to do it


> 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)

Reply via email to