Skip to content

Commit b5d63e9

Browse files
Filip Franceticfacebook-github-bot
Filip Francetic
authored andcommitted
Make isinstance/issubclass checks pass when auto-migrate mode is passed for thrift.py3.{Struct,Union}
Summary: When we're in auto-migrate mode, we want instance checks against `thrift.py3.Struct` to still pass (as there's a lot of user code that checks `isinstance(my_struct, thrift.py3.Struct)` to do some logic that is for thrift-py3 and otherwise do logic that is for thrift-py-deprecated. This makes it such that for thrift-python structs/unions, `._fbthrift_auto_migrate_enabled()` is checked, which is a bool that gets set to true when auto-migrate is enabled, so in normal build mode, `isinstance(python_struct, thrift.py3.Struct)` returns `False`, but in auto-migrate mode returns `True` Reviewed By: prakashgayasen Differential Revision: D68765988 fbshipit-source-id: 8e93fd6c526969dfe98201e3b8a3d68d31f97670
1 parent 5ffe328 commit b5d63e9

File tree

39 files changed

+698
-10
lines changed

39 files changed

+698
-10
lines changed

thrift/compiler/generate/templates/python/types/types.mustache

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class {{> structs/unadapted_name}}{{!
9393
}}{{^struct:thrift_uri}}None{{/struct:thrift_uri}}
9494

9595
{{#program:generate_immutable_types}}
96+
@classmethod
97+
def _fbthrift_auto_migrate_enabled(cls):
98+
return {{#program:py3_auto_migrate?}}True{{/program:py3_auto_migrate?}}{{^program:py3_auto_migrate?}}False{{/program:py3_auto_migrate?}}
99+
96100
@staticmethod
97101
def __get_metadata__():
98102
return _fbthrift_metadata__{{#struct:exception?}}exception{{/struct:exception?}}{{^struct:exception?}}struct{{/struct:exception?}}_{{> structs/unadapted_name}}()

thrift/compiler/test/fixtures/adapter/out/python_a/gen-python/a/thrift_types.py

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def __get_thrift_name__() -> str:
7070
def __get_thrift_uri__():
7171
return None
7272

73+
@classmethod
74+
def _fbthrift_auto_migrate_enabled(cls):
75+
return False
76+
7377
@staticmethod
7478
def __get_metadata__():
7579
return _fbthrift_metadata__struct_MyStruct()

thrift/compiler/test/fixtures/adapter/out/python_with_containers/gen-python/with_containers/thrift_types.py

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __get_thrift_name__() -> str:
5151
def __get_thrift_uri__():
5252
return None
5353

54+
@classmethod
55+
def _fbthrift_auto_migrate_enabled(cls):
56+
return False
57+
5458
@staticmethod
5559
def __get_metadata__():
5660
return _fbthrift_metadata__struct__fbthrift_unadapted_AnnotationWithContainers()
@@ -109,6 +113,10 @@ def __get_thrift_name__() -> str:
109113
def __get_thrift_uri__():
110114
return None
111115

116+
@classmethod
117+
def _fbthrift_auto_migrate_enabled(cls):
118+
return False
119+
112120
@staticmethod
113121
def __get_metadata__():
114122
return _fbthrift_metadata__struct__fbthrift_unadapted_MyStruct()

thrift/compiler/test/fixtures/basic/out/python/gen-python/test/fixtures/basic/module/thrift_types.py

+32
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def __get_thrift_name__() -> str:
136136
def __get_thrift_uri__():
137137
return "test.dev/fixtures/basic/MyStruct"
138138

139+
@classmethod
140+
def _fbthrift_auto_migrate_enabled(cls):
141+
return False
142+
139143
@staticmethod
140144
def __get_metadata__():
141145
return _fbthrift_metadata__struct_MyStruct()
@@ -213,6 +217,10 @@ def __get_thrift_name__() -> str:
213217
def __get_thrift_uri__():
214218
return "test.dev/fixtures/basic/Containers"
215219

220+
@classmethod
221+
def _fbthrift_auto_migrate_enabled(cls):
222+
return False
223+
216224
@staticmethod
217225
def __get_metadata__():
218226
return _fbthrift_metadata__struct_Containers()
@@ -257,6 +265,10 @@ def __get_thrift_name__() -> str:
257265
def __get_thrift_uri__():
258266
return "test.dev/fixtures/basic/MyDataItem"
259267

268+
@classmethod
269+
def _fbthrift_auto_migrate_enabled(cls):
270+
return False
271+
260272
@staticmethod
261273
def __get_metadata__():
262274
return _fbthrift_metadata__struct_MyDataItem()
@@ -348,6 +360,10 @@ def __get_thrift_name__() -> str:
348360
def __get_thrift_uri__():
349361
return "test.dev/fixtures/basic/MyUnion"
350362

363+
@classmethod
364+
def _fbthrift_auto_migrate_enabled(cls):
365+
return False
366+
351367
@staticmethod
352368
def __get_metadata__():
353369
return _fbthrift_metadata__struct_MyUnion()
@@ -439,6 +455,10 @@ def __get_thrift_name__() -> str:
439455
def __get_thrift_uri__():
440456
return "test.dev/fixtures/basic/MyException"
441457

458+
@classmethod
459+
def _fbthrift_auto_migrate_enabled(cls):
460+
return False
461+
442462
@staticmethod
443463
def __get_metadata__():
444464
return _fbthrift_metadata__exception_MyException()
@@ -528,6 +548,10 @@ def __get_thrift_name__() -> str:
528548
def __get_thrift_uri__():
529549
return "test.dev/fixtures/basic/MyExceptionWithMessage"
530550

551+
@classmethod
552+
def _fbthrift_auto_migrate_enabled(cls):
553+
return False
554+
531555
@staticmethod
532556
def __get_metadata__():
533557
return _fbthrift_metadata__exception_MyExceptionWithMessage()
@@ -588,6 +612,10 @@ def __get_thrift_name__() -> str:
588612
def __get_thrift_uri__():
589613
return "test.dev/fixtures/basic/ReservedKeyword"
590614

615+
@classmethod
616+
def _fbthrift_auto_migrate_enabled(cls):
617+
return False
618+
591619
@staticmethod
592620
def __get_metadata__():
593621
return _fbthrift_metadata__struct_ReservedKeyword()
@@ -646,6 +674,10 @@ def __get_thrift_name__() -> str:
646674
def __get_thrift_uri__():
647675
return "test.dev/fixtures/basic/UnionToBeRenamed"
648676

677+
@classmethod
678+
def _fbthrift_auto_migrate_enabled(cls):
679+
return False
680+
649681
@staticmethod
650682
def __get_metadata__():
651683
return _fbthrift_metadata__struct_UnionToBeRenamed()

thrift/compiler/test/fixtures/basic/out/python_service/gen-python/meta/example/thrift/service/thrift_types.py

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def __get_thrift_name__() -> str:
3939
def __get_thrift_uri__():
4040
return None
4141

42+
@classmethod
43+
def _fbthrift_auto_migrate_enabled(cls):
44+
return False
45+
4246
@staticmethod
4347
def __get_metadata__():
4448
return _fbthrift_metadata__struct_EchoRequest()
@@ -94,6 +98,10 @@ def __get_thrift_name__() -> str:
9498
def __get_thrift_uri__():
9599
return None
96100

101+
@classmethod
102+
def _fbthrift_auto_migrate_enabled(cls):
103+
return False
104+
97105
@staticmethod
98106
def __get_metadata__():
99107
return _fbthrift_metadata__struct_EchoResponse()
@@ -152,6 +160,10 @@ def __get_thrift_name__() -> str:
152160
def __get_thrift_uri__():
153161
return None
154162

163+
@classmethod
164+
def _fbthrift_auto_migrate_enabled(cls):
165+
return False
166+
155167
@staticmethod
156168
def __get_metadata__():
157169
return _fbthrift_metadata__exception_WhisperException()

thrift/compiler/test/fixtures/complex-struct/out/python/gen-python/module/thrift_types.py

+64
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def __get_thrift_name__() -> str:
7878
def __get_thrift_uri__():
7979
return None
8080

81+
@classmethod
82+
def _fbthrift_auto_migrate_enabled(cls):
83+
return False
84+
8185
@staticmethod
8286
def __get_metadata__():
8387
return _fbthrift_metadata__struct_MyStructFloatFieldThrowExp()
@@ -144,6 +148,10 @@ def __get_thrift_name__() -> str:
144148
def __get_thrift_uri__():
145149
return None
146150

151+
@classmethod
152+
def _fbthrift_auto_migrate_enabled(cls):
153+
return False
154+
147155
@staticmethod
148156
def __get_metadata__():
149157
return _fbthrift_metadata__struct_MyStructMapFloatThrowExp()
@@ -496,6 +504,10 @@ def __get_thrift_name__() -> str:
496504
def __get_thrift_uri__():
497505
return None
498506

507+
@classmethod
508+
def _fbthrift_auto_migrate_enabled(cls):
509+
return False
510+
499511
@staticmethod
500512
def __get_metadata__():
501513
return _fbthrift_metadata__struct_MyStruct()
@@ -562,6 +574,10 @@ def __get_thrift_name__() -> str:
562574
def __get_thrift_uri__():
563575
return None
564576

577+
@classmethod
578+
def _fbthrift_auto_migrate_enabled(cls):
579+
return False
580+
565581
@staticmethod
566582
def __get_metadata__():
567583
return _fbthrift_metadata__struct_SimpleStruct()
@@ -848,6 +864,10 @@ def __get_thrift_name__() -> str:
848864
def __get_thrift_uri__():
849865
return None
850866

867+
@classmethod
868+
def _fbthrift_auto_migrate_enabled(cls):
869+
return False
870+
851871
@staticmethod
852872
def __get_metadata__():
853873
return _fbthrift_metadata__struct_defaultStruct()
@@ -991,6 +1011,10 @@ def __get_thrift_name__() -> str:
9911011
def __get_thrift_uri__():
9921012
return None
9931013

1014+
@classmethod
1015+
def _fbthrift_auto_migrate_enabled(cls):
1016+
return False
1017+
9941018
@staticmethod
9951019
def __get_metadata__():
9961020
return _fbthrift_metadata__struct_MyStructTypeDef()
@@ -1035,6 +1059,10 @@ def __get_thrift_name__() -> str:
10351059
def __get_thrift_uri__():
10361060
return None
10371061

1062+
@classmethod
1063+
def _fbthrift_auto_migrate_enabled(cls):
1064+
return False
1065+
10381066
@staticmethod
10391067
def __get_metadata__():
10401068
return _fbthrift_metadata__struct_MyDataItem()
@@ -1148,6 +1176,10 @@ def __get_thrift_name__() -> str:
11481176
def __get_thrift_uri__():
11491177
return None
11501178

1179+
@classmethod
1180+
def _fbthrift_auto_migrate_enabled(cls):
1181+
return False
1182+
11511183
@staticmethod
11521184
def __get_metadata__():
11531185
return _fbthrift_metadata__struct_MyUnion()
@@ -1239,6 +1271,10 @@ def __get_thrift_name__() -> str:
12391271
def __get_thrift_uri__():
12401272
return None
12411273

1274+
@classmethod
1275+
def _fbthrift_auto_migrate_enabled(cls):
1276+
return False
1277+
12421278
@staticmethod
12431279
def __get_metadata__():
12441280
return _fbthrift_metadata__struct_MyUnionFloatFieldThrowExp()
@@ -1481,6 +1517,10 @@ def __get_thrift_name__() -> str:
14811517
def __get_thrift_uri__():
14821518
return None
14831519

1520+
@classmethod
1521+
def _fbthrift_auto_migrate_enabled(cls):
1522+
return False
1523+
14841524
@staticmethod
14851525
def __get_metadata__():
14861526
return _fbthrift_metadata__struct_ComplexNestedStruct()
@@ -1569,6 +1609,10 @@ def __get_thrift_name__() -> str:
15691609
def __get_thrift_uri__():
15701610
return None
15711611

1612+
@classmethod
1613+
def _fbthrift_auto_migrate_enabled(cls):
1614+
return False
1615+
15721616
@staticmethod
15731617
def __get_metadata__():
15741618
return _fbthrift_metadata__struct_TypeRemapped()
@@ -1616,6 +1660,10 @@ def __get_thrift_name__() -> str:
16161660
def __get_thrift_uri__():
16171661
return None
16181662

1663+
@classmethod
1664+
def _fbthrift_auto_migrate_enabled(cls):
1665+
return False
1666+
16191667
@staticmethod
16201668
def __get_metadata__():
16211669
return _fbthrift_metadata__exception_emptyXcep()
@@ -1683,6 +1731,10 @@ def __get_thrift_name__() -> str:
16831731
def __get_thrift_uri__():
16841732
return None
16851733

1734+
@classmethod
1735+
def _fbthrift_auto_migrate_enabled(cls):
1736+
return False
1737+
16861738
@staticmethod
16871739
def __get_metadata__():
16881740
return _fbthrift_metadata__exception_reqXcep()
@@ -1750,6 +1802,10 @@ def __get_thrift_name__() -> str:
17501802
def __get_thrift_uri__():
17511803
return None
17521804

1805+
@classmethod
1806+
def _fbthrift_auto_migrate_enabled(cls):
1807+
return False
1808+
17531809
@staticmethod
17541810
def __get_metadata__():
17551811
return _fbthrift_metadata__exception_optXcep()
@@ -1861,6 +1917,10 @@ def __get_thrift_name__() -> str:
18611917
def __get_thrift_uri__():
18621918
return None
18631919

1920+
@classmethod
1921+
def _fbthrift_auto_migrate_enabled(cls):
1922+
return False
1923+
18641924
@staticmethod
18651925
def __get_metadata__():
18661926
return _fbthrift_metadata__exception_complexException()
@@ -2310,6 +2370,10 @@ def __get_thrift_name__() -> str:
23102370
def __get_thrift_uri__():
23112371
return None
23122372

2373+
@classmethod
2374+
def _fbthrift_auto_migrate_enabled(cls):
2375+
return False
2376+
23132377
@staticmethod
23142378
def __get_metadata__():
23152379
return _fbthrift_metadata__struct_Containers()

0 commit comments

Comments
 (0)