Skip to content

Commit 03719f3

Browse files
Filip Franceticfacebook-github-bot
Filip Francetic
authored andcommitted
Make Struct isset work in thrift-py3 auto-migrate
Summary: This makes it so that calling `thrift.py3.Struct.isset` works on thrift-python structs. I saw these failing unit tests while working on making the instance checks work, and I figured this would only be a few lines of code required to fix it. Reviewed By: prakashgayasen, ahilger Differential Revision: D68811683 fbshipit-source-id: 52b853bbe829a42cd50755f9d1ca24c76df9958c
1 parent b5d63e9 commit 03719f3

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

thrift/lib/py3/test/auto_migrate/converter.py

-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ def test_complex_union_capi(self) -> None:
418418
self.assertEqual(complex_union.type, py3_types.Union.Type.simple_)
419419
self.assertEqual(complex_union.simple_.intField, 42)
420420

421-
@brokenInAutoMigrate()
422421
def test_optional_defaults(self) -> None:
423422
converted = python_types.OptionalDefaultsStruct()._to_py3()
424423
# pyre-fixme[6]: Expected `HasIsSet[Variable[thrift.py3.py3_types._T]]` for 1st

thrift/lib/py3/test/auto_migrate/structs.py

-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252

5353
class StructTests(unittest.TestCase):
54-
@brokenInAutoMigrate()
5554
def test_isset_Struct(self) -> None:
5655
serialized = b'{"name":"/dev/null","type":8}'
5756
file = deserialize(File, serialized, protocol=Protocol.JSON)
@@ -73,7 +72,6 @@ def test_isset_Struct(self) -> None:
7372
# param but got `File`.
7473
self.assertFalse(Struct.isset(file).type)
7574

76-
@brokenInAutoMigrate()
7775
def test_isset_repr(self) -> None:
7876
serialized = b'{"name":"/dev/null","type":8}'
7977
file = deserialize(File, serialized, protocol=Protocol.JSON)
@@ -97,7 +95,6 @@ def test_isset_Union(self) -> None:
9795
# 1st param but got `Integers`.
9896
Struct.isset(i).large
9997

100-
@brokenInAutoMigrate()
10198
def test_isset_Error(self) -> None:
10299
e = UnusedError()
103100
# pyre-fixme[6]: Expected `HasIsSet[Variable[thrift.py3.types._T]]` for 1st

thrift/lib/py3/types.pyx

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ from folly.iobuf import IOBuf
2626
from types import MappingProxyType
2727

2828
from thrift.py3.exceptions cimport GeneratedError
29+
from thrift.python.exceptions cimport GeneratedError as _fbthrift_python_GeneratedError
2930
from thrift.py3.serializer import deserialize, serialize
3031
from thrift.python.types cimport (
3132
BadEnum as _fbthrift_python_BadEnum,
@@ -37,6 +38,7 @@ from thrift.python.types import (
3738
Flag as _fbthrift_python_Flag,
3839
Struct as _fbthrift_python_Struct,
3940
StructOrUnion as _fbthrift_python_StructOrUnion,
41+
isset as _fbthrift_python_isset,
4042
Union as _fbthrift_python_Union,
4143
)
4244

@@ -49,10 +51,6 @@ __all__ = ['Struct', 'BadEnum', 'Union', 'Enum', 'Flag', 'EnumMeta']
4951

5052
_fbthrift__module_name__ = "thrift.py3.types"
5153

52-
# This isn't exposed to the module dict
53-
Object = cython.fused_type(Struct, GeneratedError)
54-
55-
5654
cdef list_eq(List self, object other):
5755
if (
5856
not isinstance(other, Iterable) or
@@ -85,8 +83,13 @@ cdef class StructMeta(type):
8583
We set helper functions here since they can't possibly confict with field names
8684
"""
8785
@staticmethod
88-
def isset(Object struct):
89-
return struct._fbthrift_isset()
86+
def isset(struct):
87+
if isinstance(struct, (_fbthrift_python_Struct, _fbthrift_python_GeneratedError, _fbthrift_python_Union)):
88+
return _IsSet(type(struct).__name__, _fbthrift_python_isset(struct))
89+
elif isinstance(struct, Struct):
90+
return (<Struct>struct)._fbthrift_isset()
91+
elif isinstance(struct, GeneratedError):
92+
return (<GeneratedError>struct)._fbthrift_isset()
9093

9194
@staticmethod
9295
def update_nested_field(obj, path_to_values):

0 commit comments

Comments
 (0)