Skip to content

Commit

Permalink
remove unnecessary try-except around thrift-python types import
Browse files Browse the repository at this point in the history
Summary: Now that issues with thrift-python validity have been addressed, it's safe to remove this `try-except`. In particular, `types.pyx` already unconditionally imports the thrift-python `.thrift_types` before this import runs, so we know this is safe:

Reviewed By: createdbysk

Differential Revision: D66461787

fbshipit-source-id: 95157bd9496f8abfba8cb0b7fc9d4dc49a59863c
  • Loading branch information
ahilger authored and facebook-github-bot committed Nov 25, 2024
1 parent ecabe01 commit 93a9011
Show file tree
Hide file tree
Showing 69 changed files with 68 additions and 506 deletions.
6 changes: 0 additions & 6 deletions thrift/compiler/generate/templates/py3/types/enum_py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ 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,10 +25,7 @@ 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
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
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.thrift_types as _fbthrift_python_types

_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,10 +8,7 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None
import module.thrift_types as _fbthrift_python_types

_fbthrift__module_name__ = "module.types"

Expand All @@ -34,12 +31,6 @@ 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,10 +8,7 @@
import enum
import thrift.py3.types
import test.fixtures.enumstrict.module.thrift_metadata as _fbthrift_python_metadata
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
import test.fixtures.enumstrict.module.thrift_types as _fbthrift_python_types

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

Expand All @@ -31,12 +28,6 @@ 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 @@ -78,12 +69,6 @@ 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 @@ -126,12 +111,6 @@ 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 @@ -191,12 +170,6 @@ 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,10 +8,7 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None
import module.thrift_types as _fbthrift_python_types

_fbthrift__module_name__ = "module.types"

Expand All @@ -33,12 +30,6 @@ 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,10 +8,7 @@
import enum
import thrift.py3.types
import test.fixtures.basic.module.thrift_metadata as _fbthrift_python_metadata
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
import test.fixtures.basic.module.thrift_types as _fbthrift_python_types

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

Expand All @@ -33,12 +30,6 @@ 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 @@ -80,12 +71,6 @@ 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,10 +8,7 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None
import module.thrift_types as _fbthrift_python_types

_fbthrift__module_name__ = "module.types"

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

_fbthrift__module_name__ = "module.types"

Expand All @@ -31,12 +28,6 @@ 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 @@ -80,12 +71,6 @@ 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 @@ -130,12 +115,6 @@ 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,10 +8,7 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None
import module.thrift_types as _fbthrift_python_types

_fbthrift__module_name__ = "module.types"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import enum
import thrift.py3.types
import test.fixtures.enums.module.thrift_metadata as _fbthrift_python_metadata
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
import test.fixtures.enums.module.thrift_types as _fbthrift_python_types

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

Expand All @@ -35,12 +32,6 @@ 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 @@ -86,12 +77,6 @@ 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 @@ -134,12 +119,6 @@ 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 @@ -185,12 +164,6 @@ 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 @@ -234,12 +207,6 @@ 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 @@ -282,12 +249,6 @@ 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 @@ -330,12 +291,6 @@ 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,10 +8,7 @@
import enum
import thrift.py3.types
import module.thrift_metadata as _fbthrift_python_metadata
try:
import module.thrift_types as _fbthrift_python_types
except Exception: # TODO(T205494848): fix thrift-python import failures
_fbthrift_python_types = None
import module.thrift_types as _fbthrift_python_types

_fbthrift__module_name__ = "module.types"

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

_fbthrift__module_name__ = "includes.types"

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

_fbthrift__module_name__ = "module.types"

Expand Down
Loading

0 comments on commit 93a9011

Please sign in to comment.