Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const values precede dataclass definitions in output #47

Closed
soaxelbrooke opened this issue Apr 23, 2024 · 3 comments · Fixed by #49
Closed

Const values precede dataclass definitions in output #47

soaxelbrooke opened this issue Apr 23, 2024 · 3 comments · Fixed by #49

Comments

@soaxelbrooke
Copy link

The following thrift:

namespace scala test

struct Foo {
    1: required string bar
    2: required i64 baz
}

const Foo foo = {
    "bar": "value",
    "baz": 1234
}

Turns into the following python:

from dataclasses import dataclass
from typing import *

foo: Any = Foo(bar="value", baz=1234)

@dataclass
class Foo:
    bar: str
    baz: int

Which results in the following exception when importing:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/stuart/code/thriftdemo/thriftpy/test.py", line 4, in <module>
    foo: Any = Foo(bar="value", baz=1234)
               ^^^
NameError: name 'Foo' is not defined
@unmade
Copy link
Owner

unmade commented Apr 23, 2024

Thank you for reporting the issue! I'll try to give it a look on weekends

@soaxelbrooke
Copy link
Author

Wow, thank you for the quick fix!

@unmade
Copy link
Owner

unmade commented Apr 28, 2024

released in version 0.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants