thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jonathan (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (THRIFT-4281) Got a NameError when using class defined in ttypes.py
Date Wed, 09 Aug 2017 10:29:00 GMT

     [ https://issues.apache.org/jira/browse/THRIFT-4281?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

jonathan updated THRIFT-4281:
-----------------------------
    Description: 
Here the problem happens.
See the error first:
    from ttypes import *
  File "../gen-py-ofs/ofs/ttypes.py", line 200, in <module>
    class FeatureGetParams:
  File "../gen-py-ofs/ofs/ttypes.py", line 210, in FeatureGetParams
    (2, TType.LIST, 'featureScenes', (TType.STRUCT,(FeatureScene, FeatureScene.thrift_spec)),
None, ), # 2
NameError: name 'FeatureScene' is not defined

Class FeatureScene is defined in line 391 of ttype.py, and is used by another class GetParams
in line of 200. Then I got this error.
I have a test.
*If I moved class FeatureScene to the front of class GetParams, the error was gone.*
I googled character of language Python, it did happen in this situation that we must define
it at the place before we refer to it.
So I have a question, if it's true, *{color:red}why doesn't ttypes.py generate two classes
in the correct order?{color}*
It confused me for a while. Hope get your reply, thank you.

Paste details of two classes for you reference:

Defined in line 391:
class FeatureScene:
  """
  Attributes:
   - featureSceneType
   - featureKeys
  """

  thrift_spec = (
    None, # 0
    (1, TType.I32, 'featureSceneType', None, None, ), # 1
    (2, TType.LIST, 'featureKeys', (TType.STRING,None), None, ), # 2
  )

Defined in line 200:
class GetParams:
  """
  Attributes:
   - orderId
   - featureScenes
  """

  thrift_spec = (
    None, # 0
    (1, TType.I64, 'orderId', None, None, ), # 1
    (2, TType.LIST, 'featureScenes', (TType.STRUCT,(FeatureScene, FeatureScene.thrift_spec)),
None, ), # 2
  )

  was:
Here the problem happens.
See the error first:
    from ttypes import *
  File "../gen-py-ofs/ofs/ttypes.py", line 200, in <module>
    class FeatureGetParams:
  File "../gen-py-ofs/ofs/ttypes.py", line 210, in FeatureGetParams
    (2, TType.LIST, 'featureScenes', (TType.STRUCT,(FeatureScene, FeatureScene.thrift_spec)),
None, ), # 2
*{color:red}NameError: name 'FeatureScene' is not defined{color}*

Class FeatureScene is defined in line 391 of ttype.py, and is used by another class GetParams
in line of 200. Then I got this error.
I have a test.
If I moved class FeatureScene to the front of class GetParams, the error was gone.
I googled character of language Python, it did happen in this situation that we must define
it at the place before we refer to it.
So I have a question, if it's true, why doesn't ttypes.py generate two classes in the correct
order?
It confused me for a while. Hope get your reply, thank you.

Paste details of two classes for you reference:

Defined in line 391:
class FeatureScene:
  """
  Attributes:
   - featureSceneType
   - featureKeys
  """

  thrift_spec = (
    None, # 0
    (1, TType.I32, 'featureSceneType', None, None, ), # 1
    (2, TType.LIST, 'featureKeys', (TType.STRING,None), None, ), # 2
  )

Defined in line 200:
class GetParams:
  """
  Attributes:
   - orderId
   - featureScenes
  """

  thrift_spec = (
    None, # 0
    (1, TType.I64, 'orderId', None, None, ), # 1
    (2, TType.LIST, 'featureScenes', (TType.STRUCT,(FeatureScene, FeatureScene.thrift_spec)),
None, ), # 2
  )


> Got a NameError when using class defined in ttypes.py
> -----------------------------------------------------
>
>                 Key: THRIFT-4281
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4281
>             Project: Thrift
>          Issue Type: Bug
>          Components: Python - Compiler
>    Affects Versions: 0.9.2
>         Environment: Thrift version 0.9.2
>            Reporter: jonathan
>
> Here the problem happens.
> See the error first:
>     from ttypes import *
>   File "../gen-py-ofs/ofs/ttypes.py", line 200, in <module>
>     class FeatureGetParams:
>   File "../gen-py-ofs/ofs/ttypes.py", line 210, in FeatureGetParams
>     (2, TType.LIST, 'featureScenes', (TType.STRUCT,(FeatureScene, FeatureScene.thrift_spec)),
None, ), # 2
> NameError: name 'FeatureScene' is not defined
> Class FeatureScene is defined in line 391 of ttype.py, and is used by another class GetParams
in line of 200. Then I got this error.
> I have a test.
> *If I moved class FeatureScene to the front of class GetParams, the error was gone.*
> I googled character of language Python, it did happen in this situation that we must
define it at the place before we refer to it.
> So I have a question, if it's true, *{color:red}why doesn't ttypes.py generate two classes
in the correct order?{color}*
> It confused me for a while. Hope get your reply, thank you.
> Paste details of two classes for you reference:
> Defined in line 391:
> class FeatureScene:
>   """
>   Attributes:
>    - featureSceneType
>    - featureKeys
>   """
>   thrift_spec = (
>     None, # 0
>     (1, TType.I32, 'featureSceneType', None, None, ), # 1
>     (2, TType.LIST, 'featureKeys', (TType.STRING,None), None, ), # 2
>   )
> Defined in line 200:
> class GetParams:
>   """
>   Attributes:
>    - orderId
>    - featureScenes
>   """
>   thrift_spec = (
>     None, # 0
>     (1, TType.I64, 'orderId', None, None, ), # 1
>     (2, TType.LIST, 'featureScenes', (TType.STRUCT,(FeatureScene, FeatureScene.thrift_spec)),
None, ), # 2
>   )



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message