Skip to content

Commit

Permalink
Revert D65737825: remove try-except thrift-python import
Browse files Browse the repository at this point in the history
Differential Revision:
D65737825

Original commit changeset: d50816072c99

Original Phabricator Diff: D65737825

fbshipit-source-id: 0ff557f777146ef678e15adc81150310b38ca1d3
  • Loading branch information
ahilger authored and facebook-github-bot committed Nov 14, 2024
1 parent 1a2ff8c commit 2fee9c1
Show file tree
Hide file tree
Showing 69 changed files with 506 additions and 68 deletions.
6 changes: 6 additions & 0 deletions thrift/compiler/generate/templates/py3/types/enum_py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class {{enum:name}}(thrift.py3.types.{{!
return "{{program:name}}.{{enum:name}}"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum {{enum:name}} doesn't define `_to_python` because couldn't import "
"{{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.thrift_types"
)

return _fbthrift_python_types.{{enum:name}}(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ are re-exported via types.pyx
import enum
import thrift.py3.types
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.thrift_metadata as _fbthrift_python_metadata
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.thrift_types as _fbthrift_python_types
try:
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "{{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand All @@ -31,6 +34,12 @@ def __get_thrift_name__():
return "module.MyEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum doesn't define `_to_python` because couldn't import "
"module.thrift_types"
)

return _fbthrift_python_types.MyEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import test.fixtures.enumstrict.module.thrift_metadata as _fbthrift_python_metadata
import test.fixtures.enumstrict.module.thrift_types as _fbthrift_python_types
try:
import test.fixtures.enumstrict.module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "test.fixtures.enumstrict.module.types"

Expand All @@ -28,6 +31,12 @@ def __get_thrift_name__():
return "module.EmptyEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum EmptyEnum doesn't define `_to_python` because couldn't import "
"test.fixtures.enumstrict.module.thrift_types"
)

return _fbthrift_python_types.EmptyEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -61,6 +70,12 @@ def __get_thrift_name__():
return "module.MyEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum doesn't define `_to_python` because couldn't import "
"test.fixtures.enumstrict.module.thrift_types"
)

return _fbthrift_python_types.MyEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -95,6 +110,12 @@ def __get_thrift_name__():
return "module.MyUseIntrinsicDefaultEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyUseIntrinsicDefaultEnum doesn't define `_to_python` because couldn't import "
"test.fixtures.enumstrict.module.thrift_types"
)

return _fbthrift_python_types.MyUseIntrinsicDefaultEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -146,6 +167,12 @@ def __get_thrift_name__():
return "module.MyBigEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyBigEnum doesn't define `_to_python` because couldn't import "
"test.fixtures.enumstrict.module.thrift_types"
)

return _fbthrift_python_types.MyBigEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand All @@ -30,6 +33,12 @@ def __get_thrift_name__():
return "module.MyEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum doesn't define `_to_python` because couldn't import "
"module.thrift_types"
)

return _fbthrift_python_types.MyEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import test.fixtures.basic.module.thrift_metadata as _fbthrift_python_metadata
import test.fixtures.basic.module.thrift_types as _fbthrift_python_types
try:
import test.fixtures.basic.module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "test.fixtures.basic.module.types"

Expand All @@ -30,6 +33,12 @@ def __get_thrift_name__():
return "module.MyEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum doesn't define `_to_python` because couldn't import "
"test.fixtures.basic.module.thrift_types"
)

return _fbthrift_python_types.MyEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -63,6 +72,12 @@ def __get_thrift_name__():
return "module.HackEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum HackEnum doesn't define `_to_python` because couldn't import "
"test.fixtures.basic.module.thrift_types"
)

return _fbthrift_python_types.HackEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand All @@ -28,6 +31,12 @@ def __get_thrift_name__():
return "module.EmptyEnum"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum EmptyEnum doesn't define `_to_python` because couldn't import "
"module.thrift_types"
)

return _fbthrift_python_types.EmptyEnum(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -63,6 +72,12 @@ def __get_thrift_name__():
return "module.City"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum City doesn't define `_to_python` because couldn't import "
"module.thrift_types"
)

return _fbthrift_python_types.City(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -98,6 +113,12 @@ def __get_thrift_name__():
return "module.Company"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum Company doesn't define `_to_python` because couldn't import "
"module.thrift_types"
)

return _fbthrift_python_types.Company(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import test.fixtures.enums.module.thrift_metadata as _fbthrift_python_metadata
import test.fixtures.enums.module.thrift_types as _fbthrift_python_types
try:
import test.fixtures.enums.module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "test.fixtures.enums.module.types"

Expand All @@ -32,6 +35,12 @@ def __get_thrift_name__():
return "module.Metasyntactic"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum Metasyntactic doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.Metasyntactic(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -69,6 +78,12 @@ def __get_thrift_name__():
return "module.MyEnum1"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum1 doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.MyEnum1(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -103,6 +118,12 @@ def __get_thrift_name__():
return "module.MyEnum2"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum2 doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.MyEnum2(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -140,6 +161,12 @@ def __get_thrift_name__():
return "module.MyEnum3"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum3 doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.MyEnum3(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -175,6 +202,12 @@ def __get_thrift_name__():
return "module.MyEnum4"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyEnum4 doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.MyEnum4(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -209,6 +242,12 @@ def __get_thrift_name__():
return "module.MyBitmaskEnum1"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyBitmaskEnum1 doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.MyBitmaskEnum1(self._fbthrift_value_)

def _to_py3(self):
Expand Down Expand Up @@ -243,6 +282,12 @@ def __get_thrift_name__():
return "module.MyBitmaskEnum2"

def _to_python(self):
if _fbthrift_python_types is None:
raise AttributeError(
"Enum MyBitmaskEnum2 doesn't define `_to_python` because couldn't import "
"test.fixtures.enums.module.thrift_types"
)

return _fbthrift_python_types.MyBitmaskEnum2(self._fbthrift_value_)

def _to_py3(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import includes.thrift_metadata as _fbthrift_python_metadata
import includes.thrift_types as _fbthrift_python_types
try:
import includes.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "includes.types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
import module.thrift_types as _fbthrift_python_types
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None

_fbthrift__module_name__ = "module.types"

Expand Down
Loading

0 comments on commit 2fee9c1

Please sign in to comment.