Skip to content

Commit be89a12

Browse files
ahilgermeta-codesync[bot]
authored andcommitted
fix undefined _fbthrift__py3_module_name bug
Summary: This fixes `NameError: name '_fbthrift__py3_module_name' is not defined`. The current template only defines this symbol when the IDL defines at least one type (`struct`, `union`, `typedef`, or `enum`). However, it's possible for an IDL to define no types but include `service` methods with containers. The symbol is needed if there are any containers, even containers of primitives. So we move the variable name definition out of the `#program:has_types?` gate. Reviewed By: stanleyz510 Differential Revision: D85972493 fbshipit-source-id: 2cf81e37159878fe2fbe07b7bd49a9d3f2209365
1 parent 3cc73f9 commit be89a12

14 files changed

Lines changed: 15 additions & 14 deletions

File tree

thrift/compiler/generate/templates/py3/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ want to include.
3434
}}
3535
{{> common/auto_generated_py}}
3636
{{#program:auto_migrate?}}
37+
{{! Note this is needed even if IDL defines no types, in the case where service has arguments that are container<primitive>}}
38+
_fbthrift__py3_module_name = "{{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types"
3739
{{#program:has_types?}}
3840
from {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.thrift_types import (
3941
{{#program:structs}}
@@ -46,7 +48,6 @@ from {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:nam
4648
{{typedef:name}},
4749
{{/program:typedefs}}
4850
)
49-
_fbthrift__py3_module_name = "{{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types"
5051
{{/program:has_types?}}
5152
{{#program:hasContainerTypes}}
5253
import importlib

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate/gen-py3/includes/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "includes.types"
78
from includes.thrift_types import (
89
Included,
910
ExampleIncluded,
1011
IncludedConstant,
1112
IncludedInt64,
1213
TransitiveFoo,
1314
)
14-
_fbthrift__py3_module_name = "includes.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate/gen-py3/module/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "module.types"
78
from module.thrift_types import (
89
MyStruct,
910
)
10-
_fbthrift__py3_module_name = "module.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate/gen-py3/transitive/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "transitive.types"
78
from transitive.thrift_types import (
89
Foo,
910
ExampleFoo,
1011
)
11-
_fbthrift__py3_module_name = "transitive.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate_includes/gen-py3/includes/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "includes.types"
78
from includes.thrift_types import (
89
Included,
910
ExampleIncluded,
1011
IncludedConstant,
1112
IncludedInt64,
1213
TransitiveFoo,
1314
)
14-
_fbthrift__py3_module_name = "includes.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate_includes/gen-py3/transitive/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "transitive.types"
78
from transitive.thrift_types import (
89
Foo,
910
ExampleFoo,
1011
)
11-
_fbthrift__py3_module_name = "transitive.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate_service/gen-py3/includes/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "includes.types"
78
from includes.thrift_types import (
89
Included,
910
ExampleIncluded,
1011
IncludedConstant,
1112
IncludedInt64,
1213
TransitiveFoo,
1314
)
14-
_fbthrift__py3_module_name = "includes.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate_service/gen-py3/module/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "module.types"
78
from module.thrift_types import (
89
MyStruct,
910
)
10-
_fbthrift__py3_module_name = "module.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate_service/gen-py3/service/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "service.types"
78
from service.thrift_types import (
89
IncludesIncluded,
910
IncludesTransitiveFoo,
1011
)
11-
_fbthrift__py3_module_name = "service.types"

thrift/compiler/test/fixtures/includes/out/py3_auto_migrate_service/gen-py3/transitive/types_auto_FBTHRIFT_ONLY_DO_NOT_USE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
55
# @generated
66
#
7+
_fbthrift__py3_module_name = "transitive.types"
78
from transitive.thrift_types import (
89
Foo,
910
ExampleFoo,
1011
)
11-
_fbthrift__py3_module_name = "transitive.types"

0 commit comments

Comments
 (0)