diff --git a/third-party/thrift/src/thrift/compiler/generate/t_mstch_py3_generator.cc b/third-party/thrift/src/thrift/compiler/generate/t_mstch_py3_generator.cc index dcd99c4cb0fe8e..7ef01ddde7784c 100644 --- a/third-party/thrift/src/thrift/compiler/generate/t_mstch_py3_generator.cc +++ b/third-party/thrift/src/thrift/compiler/generate/t_mstch_py3_generator.cc @@ -112,7 +112,6 @@ std::string get_cpp_template(const t_type& type) { bool is_hidden(const t_named& node) { return node.has_annotation("py3.hidden") || - node.find_structured_annotation_or_null(kCppAdapterUri) || node.find_structured_annotation_or_null(kPythonPy3HiddenUri); } @@ -807,7 +806,9 @@ class py3_mstch_struct : public mstch_struct { py3_fields_.begin(), py3_fields_.end(), [this](const t_field* field) { - bool hidden = is_hidden(*field); + bool hidden = field->has_annotation("py3.hidden") || + field->find_structured_annotation_or_null( + kPythonPy3HiddenUri); this->hidden_fields |= hidden; return hidden; }), diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/py3/gen-py3/module/types.h b/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/py3/gen-py3/module/types.h index 0e498845080ab4..9f65a1582f0bb7 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/py3/gen-py3/module/types.h +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/py3/gen-py3/module/types.h @@ -36,15 +36,36 @@ inline void reset_field<::facebook::thrift::test::Foo>( ::facebook::thrift::test::Foo& obj, uint16_t index) { switch (index) { case 0: - obj.setField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().setField_ref()); + obj.intField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().intField_ref()); return; case 1: - obj.optionalSetField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalSetField_ref()); + obj.optionalIntField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalIntField_ref()); return; case 2: - obj.longField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().longField_ref()); + obj.intFieldWithDefault_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().intFieldWithDefault_ref()); return; case 3: + obj.setField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().setField_ref()); + return; + case 4: + obj.optionalSetField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalSetField_ref()); + return; + case 5: + obj.mapField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().mapField_ref()); + return; + case 6: + obj.optionalMapField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalMapField_ref()); + return; + case 7: + obj.binaryField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().binaryField_ref()); + return; + case 8: + obj.longField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().longField_ref()); + return; + case 9: + obj.adaptedLongField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().adaptedLongField_ref()); + return; + case 10: obj.doubleAdaptedField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().doubleAdaptedField_ref()); return; } @@ -55,12 +76,24 @@ inline void reset_field<::facebook::thrift::test::Bar>( ::facebook::thrift::test::Bar& obj, uint16_t index) { switch (index) { case 0: - obj.structListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().structListField_ref()); + obj.structField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().structField_ref()); return; case 1: - obj.optionalStructListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalStructListField_ref()); + obj.optionalStructField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalStructField_ref()); return; case 2: + obj.structListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().structListField_ref()); + return; + case 3: + obj.optionalStructListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalStructListField_ref()); + return; + case 4: + obj.unionField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().unionField_ref()); + return; + case 5: + obj.optionalUnionField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalUnionField_ref()); + return; + case 6: obj.adaptedStructField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().adaptedStructField_ref()); return; } @@ -70,6 +103,18 @@ template<> inline void reset_field<::facebook::thrift::test::StructWithFieldAdapter>( ::facebook::thrift::test::StructWithFieldAdapter& obj, uint16_t index) { switch (index) { + case 0: + obj.field_ref().copy_from(default_inst<::facebook::thrift::test::StructWithFieldAdapter>().field_ref()); + return; + case 1: + obj.shared_field_ref().reset(); + return; + case 2: + obj.opt_shared_field_ref().reset(); + return; + case 3: + obj.opt_boxed_field_ref().copy_from(default_inst<::facebook::thrift::test::StructWithFieldAdapter>().opt_boxed_field_ref()); + return; } } @@ -77,6 +122,15 @@ template<> inline void reset_field<::facebook::thrift::test::TerseAdaptedFields>( ::facebook::thrift::test::TerseAdaptedFields& obj, uint16_t index) { switch (index) { + case 0: + obj.int_field_ref().copy_from(default_inst<::facebook::thrift::test::TerseAdaptedFields>().int_field_ref()); + return; + case 1: + obj.string_field_ref().copy_from(default_inst<::facebook::thrift::test::TerseAdaptedFields>().string_field_ref()); + return; + case 2: + obj.set_field_ref().copy_from(default_inst<::facebook::thrift::test::TerseAdaptedFields>().set_field_ref()); + return; } } @@ -131,11 +185,29 @@ inline void reset_field<::facebook::thrift::test::AdaptTestStruct>( obj.custom_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().custom_ref()); return; case 2: - obj.meta_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().meta_ref()); + obj.timeout_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().timeout_ref()); return; case 3: + obj.data_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().data_ref()); + return; + case 4: + obj.meta_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().meta_ref()); + return; + case 5: obj.indirectionString_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().indirectionString_ref()); return; + case 6: + obj.string_data_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().string_data_ref()); + return; + case 7: + obj.double_wrapped_bool_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().double_wrapped_bool_ref()); + return; + case 8: + obj.double_wrapped_integer_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().double_wrapped_integer_ref()); + return; + case 9: + obj.binary_data_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().binary_data_ref()); + return; } } @@ -165,30 +237,48 @@ inline void reset_field<::facebook::thrift::test::AdaptTemplatedTestStruct>( obj.adaptedString_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedString_ref()); return; case 7: - obj.adaptedBoolDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedBoolDefault_ref()); + obj.adaptedList_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedList_ref()); return; case 8: - obj.adaptedByteDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedByteDefault_ref()); + obj.adaptedSet_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedSet_ref()); return; case 9: - obj.adaptedShortDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedShortDefault_ref()); + obj.adaptedMap_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedMap_ref()); return; case 10: - obj.adaptedIntegerDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedIntegerDefault_ref()); + obj.adaptedBoolDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedBoolDefault_ref()); return; case 11: - obj.adaptedLongDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedLongDefault_ref()); + obj.adaptedByteDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedByteDefault_ref()); return; case 12: - obj.adaptedDoubleDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedDoubleDefault_ref()); + obj.adaptedShortDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedShortDefault_ref()); return; case 13: - obj.adaptedStringDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedStringDefault_ref()); + obj.adaptedIntegerDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedIntegerDefault_ref()); return; case 14: - obj.adaptedEnum_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedEnum_ref()); + obj.adaptedLongDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedLongDefault_ref()); return; case 15: + obj.adaptedDoubleDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedDoubleDefault_ref()); + return; + case 16: + obj.adaptedStringDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedStringDefault_ref()); + return; + case 17: + obj.adaptedEnum_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedEnum_ref()); + return; + case 18: + obj.adaptedListDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedListDefault_ref()); + return; + case 19: + obj.adaptedSetDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedSetDefault_ref()); + return; + case 20: + obj.adaptedMapDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedMapDefault_ref()); + return; + case 21: obj.doubleTypedefBool_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().doubleTypedefBool_ref()); return; } @@ -219,12 +309,15 @@ inline void reset_field<::facebook::thrift::test::StructFieldAdaptedStruct>( ::facebook::thrift::test::StructFieldAdaptedStruct& obj, uint16_t index) { switch (index) { case 0: - obj.adaptedTypedef_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().adaptedTypedef_ref()); + obj.adaptedStruct_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().adaptedStruct_ref()); return; case 1: - obj.directlyAdapted_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().directlyAdapted_ref()); + obj.adaptedTypedef_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().adaptedTypedef_ref()); return; case 2: + obj.directlyAdapted_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().directlyAdapted_ref()); + return; + case 3: obj.typedefOfAdapted_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().typedefOfAdapted_ref()); return; } @@ -274,6 +367,9 @@ template<> inline void reset_field<::facebook::thrift::test::AlsoMoveOnly>( ::facebook::thrift::test::AlsoMoveOnly& obj, uint16_t index) { switch (index) { + case 0: + obj.ptr_ref().copy_from(default_inst<::facebook::thrift::test::AlsoMoveOnly>().ptr_ref()); + return; } } @@ -289,8 +385,14 @@ inline void reset_field<::facebook::thrift::test::CountingStruct>( ::facebook::thrift::test::CountingStruct& obj, uint16_t index) { switch (index) { case 0: + obj.regularInt_ref().copy_from(default_inst<::facebook::thrift::test::CountingStruct>().regularInt_ref()); + return; + case 1: obj.countingInt_ref().copy_from(default_inst<::facebook::thrift::test::CountingStruct>().countingInt_ref()); return; + case 2: + obj.regularString_ref().copy_from(default_inst<::facebook::thrift::test::CountingStruct>().regularString_ref()); + return; } } diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/builders.py b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/builders.py index c0b2d56b01aac3..004038710e01c0 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/builders.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/builders.py @@ -200,20 +200,24 @@ class AdaptedStructWithInternBox_Builder(thrift.py3.builder.StructBuilder): _struct_type = _fbthrift_struct_type__AdaptedStructWithInternBox def __init__(self): - pass + self.field1: _typing.Any = None + self.field2: _typing.Any = None def __iter__(self): - pass + yield "field1", self.field1 + yield "field2", self.field2 _fbthrift_struct_type__AdaptedStructWithTerseInternBox = _module_types.AdaptedStructWithTerseInternBox class AdaptedStructWithTerseInternBox_Builder(thrift.py3.builder.StructBuilder): _struct_type = _fbthrift_struct_type__AdaptedStructWithTerseInternBox def __init__(self): - pass + self.field1: _typing.Any = None + self.field2: _typing.Any = None def __iter__(self): - pass + yield "field1", self.field1 + yield "field2", self.field2 _fbthrift_struct_type__StructWithRefTypeUnique = _module_types.StructWithRefTypeUnique class StructWithRefTypeUnique_Builder(thrift.py3.builder.StructBuilder): diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.h b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.h index f3e38bb97111f3..57b47e9e979ab9 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.h +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.h @@ -204,6 +204,12 @@ template<> inline void reset_field<::cpp2::AdaptedStructWithInternBox>( ::cpp2::AdaptedStructWithInternBox& obj, uint16_t index) { switch (index) { + case 0: + obj.field1_ref().copy_from(default_inst<::cpp2::AdaptedStructWithInternBox>().field1_ref()); + return; + case 1: + obj.field2_ref().copy_from(default_inst<::cpp2::AdaptedStructWithInternBox>().field2_ref()); + return; } } @@ -211,6 +217,12 @@ template<> inline void reset_field<::cpp2::AdaptedStructWithTerseInternBox>( ::cpp2::AdaptedStructWithTerseInternBox& obj, uint16_t index) { switch (index) { + case 0: + obj.field1_ref().copy_from(default_inst<::cpp2::AdaptedStructWithTerseInternBox>().field1_ref()); + return; + case 1: + obj.field2_ref().copy_from(default_inst<::cpp2::AdaptedStructWithTerseInternBox>().field2_ref()); + return; } } diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pxd b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pxd index f08993b12f4124..47fcfb10fce0f4 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pxd +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pxd @@ -271,6 +271,8 @@ cdef extern from "thrift/compiler/test/fixtures/refs/gen-cpp2/module_types_custo bint operator>(cAdaptedStructWithInternBox&) bint operator<=(cAdaptedStructWithInternBox&) bint operator>=(cAdaptedStructWithInternBox&) + __field_ref[cEmpty] field1_ref "field1_ref" () + __field_ref[cMyField] field2_ref "field2_ref" () cdef cppclass cAdaptedStructWithTerseInternBox "::cpp2::AdaptedStructWithTerseInternBox": @@ -282,6 +284,8 @@ cdef extern from "thrift/compiler/test/fixtures/refs/gen-cpp2/module_types_custo bint operator>(cAdaptedStructWithTerseInternBox&) bint operator<=(cAdaptedStructWithTerseInternBox&) bint operator>=(cAdaptedStructWithTerseInternBox&) + __terse_field_ref[cEmpty] field1_ref "field1_ref" () + __terse_field_ref[cMyField] field2_ref "field2_ref" () cdef cppclass cStructWithRefTypeUnique "::cpp2::StructWithRefTypeUnique": @@ -555,6 +559,10 @@ cdef class StructWithTerseInternBox(thrift.py3.types.Struct): cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct): cdef shared_ptr[cAdaptedStructWithInternBox] _cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE cdef _fbthrift_types_fields.__AdaptedStructWithInternBox_FieldsSetter _fields_setter + cdef inline object field1_impl(self) + cdef inline object field2_impl(self) + cdef Empty __fbthrift_cached_field1 + cdef MyField __fbthrift_cached_field2 @staticmethod cdef _create_FBTHRIFT_ONLY_DO_NOT_USE(shared_ptr[cAdaptedStructWithInternBox]) @@ -564,6 +572,10 @@ cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct): cdef class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct): cdef shared_ptr[cAdaptedStructWithTerseInternBox] _cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE cdef _fbthrift_types_fields.__AdaptedStructWithTerseInternBox_FieldsSetter _fields_setter + cdef inline object field1_impl(self) + cdef inline object field2_impl(self) + cdef Empty __fbthrift_cached_field1 + cdef MyField __fbthrift_cached_field2 @staticmethod cdef _create_FBTHRIFT_ONLY_DO_NOT_USE(shared_ptr[cAdaptedStructWithTerseInternBox]) diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyi b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyi index f1d733bb68de42..68870b506e5ddf 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyi +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyi @@ -509,15 +509,23 @@ class StructWithTerseInternBox(thrift.py3.types.Struct, _typing.Hashable): class AdaptedStructWithInternBox(thrift.py3.types.Struct, _typing.Hashable): class __fbthrift_IsSet: + field1: bool + field2: bool pass + field1: _typing.Final[Empty] = ... + field2: _typing.Final[MyField] = ... def __init__( - self, + self, *, + field1: _typing.Optional[Empty]=None, + field2: _typing.Optional[MyField]=None ) -> None: ... def __call__( - self, + self, *, + field1: _typing.Union[Empty, None]=None, + field2: _typing.Union[MyField, None]=None ) -> AdaptedStructWithInternBox: ... def __reduce__(self) -> _typing.Tuple[_typing.Callable, _typing.Tuple[_typing.Type['AdaptedStructWithInternBox'], bytes]]: ... @@ -537,13 +545,19 @@ class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct, _typing.Hashable) class __fbthrift_IsSet: pass + field1: _typing.Final[Empty] = ... + field2: _typing.Final[MyField] = ... def __init__( - self, + self, *, + field1: _typing.Optional[Empty]=None, + field2: _typing.Optional[MyField]=None ) -> None: ... def __call__( - self, + self, *, + field1: _typing.Union[Empty, None]=None, + field2: _typing.Union[MyField, None]=None ) -> AdaptedStructWithTerseInternBox: ... def __reduce__(self) -> _typing.Tuple[_typing.Callable, _typing.Tuple[_typing.Type['AdaptedStructWithTerseInternBox'], bytes]]: ... diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx index c35fcc581e44b7..7459bf1e42f3e0 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx @@ -1963,13 +1963,22 @@ cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct): super().__init__(**kwargs) def __call__(AdaptedStructWithInternBox self, **kwargs): - return self + if not kwargs: + return self + cdef AdaptedStructWithInternBox __fbthrift_inst = AdaptedStructWithInternBox.__new__(AdaptedStructWithInternBox) + __fbthrift_inst._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE = make_shared[cAdaptedStructWithInternBox](deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + __fbthrift_inst._fields_setter = _fbthrift_types_fields.__AdaptedStructWithInternBox_FieldsSetter._fbthrift_create(__fbthrift_inst._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE.get()) + for __fbthrift_name, _fbthrift_value in kwargs.items(): + __fbthrift_inst._fbthrift_set_field(__fbthrift_name, _fbthrift_value) + return __fbthrift_inst cdef void _fbthrift_set_field(self, str name, object value) except *: self._fields_setter.set_field(name.encode("utf-8"), value) cdef object _fbthrift_isset(self): return _fbthrift_IsSet("AdaptedStructWithInternBox", { + "field1": deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).field1_ref().has_value(), + "field2": deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).field2_ref().has_value(), }) @staticmethod @@ -1978,6 +1987,24 @@ cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct): __fbthrift_inst._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE = cmove(cpp_obj) return __fbthrift_inst + cdef inline field1_impl(self): + if self.__fbthrift_cached_field1 is None: + self.__fbthrift_cached_field1 = Empty._create_FBTHRIFT_ONLY_DO_NOT_USE(__reference_shared_ptr(deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).field1_ref().ref(), self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + return self.__fbthrift_cached_field1 + + @property + def field1(self): + return self.field1_impl() + + cdef inline field2_impl(self): + if self.__fbthrift_cached_field2 is None: + self.__fbthrift_cached_field2 = MyField._create_FBTHRIFT_ONLY_DO_NOT_USE(__reference_shared_ptr(deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).field2_ref().ref(), self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + return self.__fbthrift_cached_field2 + + @property + def field2(self): + return self.field2_impl() + def __hash__(AdaptedStructWithInternBox self): return super().__hash__() @@ -2017,16 +2044,13 @@ cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct): def __get_thrift_name__(): return "module.AdaptedStructWithInternBox" - __fbthrift_field_name_list = [ - ] - @classmethod def _fbthrift_get_field_name_by_index(cls, idx): - return cls.__fbthrift_field_name_list[idx] + return __sv_to_str(__get_field_name_by_index[cAdaptedStructWithInternBox](idx)) @classmethod def _fbthrift_get_struct_size(cls): - return 0 + return 2 cdef _fbthrift_iobuf.IOBuf _fbthrift_serialize(AdaptedStructWithInternBox self, __Protocol proto): cdef unique_ptr[_fbthrift_iobuf.cIOBuf] data @@ -2067,7 +2091,14 @@ cdef class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct): super().__init__(**kwargs) def __call__(AdaptedStructWithTerseInternBox self, **kwargs): - return self + if not kwargs: + return self + cdef AdaptedStructWithTerseInternBox __fbthrift_inst = AdaptedStructWithTerseInternBox.__new__(AdaptedStructWithTerseInternBox) + __fbthrift_inst._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE = make_shared[cAdaptedStructWithTerseInternBox](deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + __fbthrift_inst._fields_setter = _fbthrift_types_fields.__AdaptedStructWithTerseInternBox_FieldsSetter._fbthrift_create(__fbthrift_inst._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE.get()) + for __fbthrift_name, _fbthrift_value in kwargs.items(): + __fbthrift_inst._fbthrift_set_field(__fbthrift_name, _fbthrift_value) + return __fbthrift_inst cdef void _fbthrift_set_field(self, str name, object value) except *: self._fields_setter.set_field(name.encode("utf-8"), value) @@ -2082,6 +2113,24 @@ cdef class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct): __fbthrift_inst._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE = cmove(cpp_obj) return __fbthrift_inst + cdef inline field1_impl(self): + if self.__fbthrift_cached_field1 is None: + self.__fbthrift_cached_field1 = Empty._create_FBTHRIFT_ONLY_DO_NOT_USE(__reference_shared_ptr(deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).field1_ref().ref(), self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + return self.__fbthrift_cached_field1 + + @property + def field1(self): + return self.field1_impl() + + cdef inline field2_impl(self): + if self.__fbthrift_cached_field2 is None: + self.__fbthrift_cached_field2 = MyField._create_FBTHRIFT_ONLY_DO_NOT_USE(__reference_shared_ptr(deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).field2_ref().ref(), self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + return self.__fbthrift_cached_field2 + + @property + def field2(self): + return self.field2_impl() + def __hash__(AdaptedStructWithTerseInternBox self): return super().__hash__() @@ -2121,16 +2170,13 @@ cdef class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct): def __get_thrift_name__(): return "module.AdaptedStructWithTerseInternBox" - __fbthrift_field_name_list = [ - ] - @classmethod def _fbthrift_get_field_name_by_index(cls, idx): - return cls.__fbthrift_field_name_list[idx] + return __sv_to_str(__get_field_name_by_index[cAdaptedStructWithTerseInternBox](idx)) @classmethod def _fbthrift_get_struct_size(cls): - return 0 + return 2 cdef _fbthrift_iobuf.IOBuf _fbthrift_serialize(AdaptedStructWithTerseInternBox self, __Protocol proto): cdef unique_ptr[_fbthrift_iobuf.cIOBuf] data diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pxd b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pxd index afdbc54d66c4b5..4238e24fccc754 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pxd +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pxd @@ -196,6 +196,8 @@ cdef class __AdaptedStructWithInternBox_FieldsSetter(__StructFieldsSetter): @staticmethod cdef __AdaptedStructWithInternBox_FieldsSetter _fbthrift_create(_module_types.cAdaptedStructWithInternBox* struct_cpp_obj) + cdef void _set_field_0(self, _fbthrift_value) except * + cdef void _set_field_1(self, _fbthrift_value) except * ctypedef void (*__AdaptedStructWithTerseInternBox_FieldsSetterFunc)(__AdaptedStructWithTerseInternBox_FieldsSetter, object) except * @@ -206,6 +208,8 @@ cdef class __AdaptedStructWithTerseInternBox_FieldsSetter(__StructFieldsSetter): @staticmethod cdef __AdaptedStructWithTerseInternBox_FieldsSetter _fbthrift_create(_module_types.cAdaptedStructWithTerseInternBox* struct_cpp_obj) + cdef void _set_field_0(self, _fbthrift_value) except * + cdef void _set_field_1(self, _fbthrift_value) except * ctypedef void (*__StructWithRefTypeUnique_FieldsSetterFunc)(__StructWithRefTypeUnique_FieldsSetter, object) except * diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pyx b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pyx index ebf8956f7f0f45..f15c991e389850 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pyx +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_fields.pyx @@ -560,6 +560,8 @@ cdef class __AdaptedStructWithInternBox_FieldsSetter(__StructFieldsSetter): cdef __AdaptedStructWithInternBox_FieldsSetter _fbthrift_create(_module_types.cAdaptedStructWithInternBox* struct_cpp_obj): cdef __AdaptedStructWithInternBox_FieldsSetter __fbthrift_inst = __AdaptedStructWithInternBox_FieldsSetter.__new__(__AdaptedStructWithInternBox_FieldsSetter) __fbthrift_inst._struct_cpp_obj = struct_cpp_obj + __fbthrift_inst._setters[__cstring_view("field1")] = __AdaptedStructWithInternBox_FieldsSetter._set_field_0 + __fbthrift_inst._setters[__cstring_view("field2")] = __AdaptedStructWithInternBox_FieldsSetter._set_field_1 return __fbthrift_inst cdef void set_field(__AdaptedStructWithInternBox_FieldsSetter self, const char* name, object value) except *: @@ -569,6 +571,24 @@ cdef class __AdaptedStructWithInternBox_FieldsSetter(__StructFieldsSetter): raise TypeError(f"invalid field name {name.decode('utf-8')}") deref(found).second(self, value) + cdef void _set_field_0(self, _fbthrift_value) except *: + # for field field1 + if _fbthrift_value is None: + __reset_field[_module_types.cAdaptedStructWithInternBox](deref(self._struct_cpp_obj), 0) + return + if not isinstance(_fbthrift_value, _module_types.Empty): + raise TypeError(f'field1 is not a { _module_types.Empty !r}.') + deref(self._struct_cpp_obj).field1_ref().assign(deref((<_module_types.Empty?> _fbthrift_value)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + + cdef void _set_field_1(self, _fbthrift_value) except *: + # for field field2 + if _fbthrift_value is None: + __reset_field[_module_types.cAdaptedStructWithInternBox](deref(self._struct_cpp_obj), 1) + return + if not isinstance(_fbthrift_value, _module_types.MyField): + raise TypeError(f'field2 is not a { _module_types.MyField !r}.') + deref(self._struct_cpp_obj).field2_ref().assign(deref((<_module_types.MyField?> _fbthrift_value)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + @__cython.auto_pickle(False) cdef class __AdaptedStructWithTerseInternBox_FieldsSetter(__StructFieldsSetter): @@ -577,6 +597,8 @@ cdef class __AdaptedStructWithTerseInternBox_FieldsSetter(__StructFieldsSetter): cdef __AdaptedStructWithTerseInternBox_FieldsSetter _fbthrift_create(_module_types.cAdaptedStructWithTerseInternBox* struct_cpp_obj): cdef __AdaptedStructWithTerseInternBox_FieldsSetter __fbthrift_inst = __AdaptedStructWithTerseInternBox_FieldsSetter.__new__(__AdaptedStructWithTerseInternBox_FieldsSetter) __fbthrift_inst._struct_cpp_obj = struct_cpp_obj + __fbthrift_inst._setters[__cstring_view("field1")] = __AdaptedStructWithTerseInternBox_FieldsSetter._set_field_0 + __fbthrift_inst._setters[__cstring_view("field2")] = __AdaptedStructWithTerseInternBox_FieldsSetter._set_field_1 return __fbthrift_inst cdef void set_field(__AdaptedStructWithTerseInternBox_FieldsSetter self, const char* name, object value) except *: @@ -586,6 +608,24 @@ cdef class __AdaptedStructWithTerseInternBox_FieldsSetter(__StructFieldsSetter): raise TypeError(f"invalid field name {name.decode('utf-8')}") deref(found).second(self, value) + cdef void _set_field_0(self, _fbthrift_value) except *: + # for field field1 + if _fbthrift_value is None: + __reset_field[_module_types.cAdaptedStructWithTerseInternBox](deref(self._struct_cpp_obj), 0) + return + if not isinstance(_fbthrift_value, _module_types.Empty): + raise TypeError(f'field1 is not a { _module_types.Empty !r}.') + deref(self._struct_cpp_obj).field1_ref().assign(deref((<_module_types.Empty?> _fbthrift_value)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + + cdef void _set_field_1(self, _fbthrift_value) except *: + # for field field2 + if _fbthrift_value is None: + __reset_field[_module_types.cAdaptedStructWithTerseInternBox](deref(self._struct_cpp_obj), 1) + return + if not isinstance(_fbthrift_value, _module_types.MyField): + raise TypeError(f'field2 is not a { _module_types.MyField !r}.') + deref(self._struct_cpp_obj).field2_ref().assign(deref((<_module_types.MyField?> _fbthrift_value)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + @__cython.auto_pickle(False) cdef class __StructWithRefTypeUnique_FieldsSetter(__StructFieldsSetter): diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_reflection.py b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_reflection.py index e9d39be6c28e7f..6c416584386735 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_reflection.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types_reflection.py @@ -629,6 +629,32 @@ def get_reflection__AdaptedStructWithInternBox() -> __StructSpec: annotations={ }, ) + spec.add_field( + __FieldSpec._fbthrift_create( + id=1, + name="field1", + py_name="field1", + type=_module_types.Empty, + kind=__NumberType.NOT_A_NUMBER, + qualifier=__Qualifier.UNQUALIFIED, + default=None, + annotations={ + }, + ), + ) + spec.add_field( + __FieldSpec._fbthrift_create( + id=2, + name="field2", + py_name="field2", + type=_module_types.MyField, + kind=__NumberType.NOT_A_NUMBER, + qualifier=__Qualifier.UNQUALIFIED, + default=None, + annotations={ + }, + ), + ) return spec def get_reflection__AdaptedStructWithTerseInternBox() -> __StructSpec: spec: __StructSpec = __StructSpec._fbthrift_create( @@ -637,6 +663,32 @@ def get_reflection__AdaptedStructWithTerseInternBox() -> __StructSpec: annotations={ }, ) + spec.add_field( + __FieldSpec._fbthrift_create( + id=1, + name="field1", + py_name="field1", + type=_module_types.Empty, + kind=__NumberType.NOT_A_NUMBER, + qualifier=__Qualifier.UNQUALIFIED, + default=None, + annotations={ + }, + ), + ) + spec.add_field( + __FieldSpec._fbthrift_create( + id=2, + name="field2", + py_name="field2", + type=_module_types.MyField, + kind=__NumberType.NOT_A_NUMBER, + qualifier=__Qualifier.UNQUALIFIED, + default=None, + annotations={ + }, + ), + ) return spec def get_reflection__StructWithRefTypeUnique() -> __StructSpec: spec: __StructSpec = __StructSpec._fbthrift_create( diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/out/py3/gen-py3/terse_write/types.h b/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/out/py3/gen-py3/terse_write/types.h index 4e2af0c1428232..8ed85750281bfc 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/out/py3/gen-py3/terse_write/types.h +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/terse_write/out/py3/gen-py3/terse_write/types.h @@ -240,6 +240,12 @@ inline void reset_field<::facebook::thrift::test::terse_write::AdaptedFields>( case 0: obj.field1_ref().copy_from(default_inst<::facebook::thrift::test::terse_write::AdaptedFields>().field1_ref()); return; + case 1: + obj.field2_ref().copy_from(default_inst<::facebook::thrift::test::terse_write::AdaptedFields>().field2_ref()); + return; + case 2: + obj.field3_ref().copy_from(default_inst<::facebook::thrift::test::terse_write::AdaptedFields>().field3_ref()); + return; } } diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/builders.py b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/builders.py index 6e550bfc943c47..bcc53612cdbc5d 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/builders.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/builders.py @@ -163,12 +163,14 @@ class MinPaddingWithCustomType_Builder(thrift.py3.builder.StructBuilder): def __init__(self): self.small: _typing.Optional[int] = None self.big: _typing.Optional[int] = None + self.medium: _typing.Optional[int] = None self.biggish: _typing.Optional[int] = None self.tiny: _typing.Optional[int] = None def __iter__(self): yield "small", self.small yield "big", self.big + yield "medium", self.medium yield "biggish", self.biggish yield "tiny", self.tiny diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pxd b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pxd index 36a8a2297d4f86..0f9835a68d011b 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pxd +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pxd @@ -607,6 +607,7 @@ cdef extern from "thrift/compiler/test/fixtures/types/gen-cpp2/module_types_cust bint operator>=(cMinPaddingWithCustomType&) __terse_field_ref[cint8_t] small_ref "small_ref" () __terse_field_ref[cint64_t] big_ref "big_ref" () + __terse_field_ref[cint16_t] medium_ref "medium_ref" () __terse_field_ref[cint32_t] biggish_ref "biggish_ref" () __terse_field_ref[cint8_t] tiny_ref "tiny_ref" () @@ -1006,6 +1007,7 @@ cdef class MinPaddingWithCustomType(thrift.py3.types.Struct): cdef _fbthrift_types_fields.__MinPaddingWithCustomType_FieldsSetter _fields_setter cdef inline object small_impl(self) cdef inline object big_impl(self) + cdef inline object medium_impl(self) cdef inline object biggish_impl(self) cdef inline object tiny_impl(self) diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyi b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyi index 54657c30b3dda7..0229bfeb1fa566 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyi +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyi @@ -446,6 +446,7 @@ class MinPaddingWithCustomType(thrift.py3.types.Struct, _typing.Hashable): small: _typing.Final[int] = ... big: _typing.Final[int] = ... + medium: _typing.Final[int] = ... biggish: _typing.Final[int] = ... tiny: _typing.Final[int] = ... @@ -453,6 +454,7 @@ class MinPaddingWithCustomType(thrift.py3.types.Struct, _typing.Hashable): self, *, small: _typing.Optional[int]=None, big: _typing.Optional[int]=None, + medium: _typing.Optional[int]=None, biggish: _typing.Optional[int]=None, tiny: _typing.Optional[int]=None ) -> None: ... @@ -461,6 +463,7 @@ class MinPaddingWithCustomType(thrift.py3.types.Struct, _typing.Hashable): self, *, small: _typing.Union[int, None]=None, big: _typing.Union[int, None]=None, + medium: _typing.Union[int, None]=None, biggish: _typing.Union[int, None]=None, tiny: _typing.Union[int, None]=None ) -> MinPaddingWithCustomType: ... diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx index 8e16ffb63be0a3..43fd69a0e7b795 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx @@ -1547,6 +1547,13 @@ cdef class MinPaddingWithCustomType(thrift.py3.types.Struct): def big(self): return self.big_impl() + cdef inline medium_impl(self): + return deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).medium_ref().value() + + @property + def medium(self): + return self.medium_impl() + cdef inline biggish_impl(self): return deref(self._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE).biggish_ref().value() @@ -1600,20 +1607,13 @@ cdef class MinPaddingWithCustomType(thrift.py3.types.Struct): def __get_thrift_name__(): return "module.MinPaddingWithCustomType" - __fbthrift_field_name_list = [ - 'small', - 'big', - 'biggish', - 'tiny', - ] - @classmethod def _fbthrift_get_field_name_by_index(cls, idx): - return cls.__fbthrift_field_name_list[idx] + return __sv_to_str(__get_field_name_by_index[cMinPaddingWithCustomType](idx)) @classmethod def _fbthrift_get_struct_size(cls): - return 4 + return 5 cdef _fbthrift_iobuf.IOBuf _fbthrift_serialize(MinPaddingWithCustomType self, __Protocol proto): cdef unique_ptr[_fbthrift_iobuf.cIOBuf] data diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pxd b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pxd index fd95ff0c37b2af..58efab866da286 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pxd +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pxd @@ -192,6 +192,7 @@ cdef class __MinPaddingWithCustomType_FieldsSetter(__StructFieldsSetter): cdef void _set_field_1(self, _fbthrift_value) except * cdef void _set_field_2(self, _fbthrift_value) except * cdef void _set_field_3(self, _fbthrift_value) except * + cdef void _set_field_4(self, _fbthrift_value) except * ctypedef void (*__MyStruct_FieldsSetterFunc)(__MyStruct_FieldsSetter, object) except * diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pyx b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pyx index 437c92442e1dfd..c12265c02f107f 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pyx +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_fields.pyx @@ -474,8 +474,9 @@ cdef class __MinPaddingWithCustomType_FieldsSetter(__StructFieldsSetter): __fbthrift_inst._struct_cpp_obj = struct_cpp_obj __fbthrift_inst._setters[__cstring_view("small")] = __MinPaddingWithCustomType_FieldsSetter._set_field_0 __fbthrift_inst._setters[__cstring_view("big")] = __MinPaddingWithCustomType_FieldsSetter._set_field_1 - __fbthrift_inst._setters[__cstring_view("biggish")] = __MinPaddingWithCustomType_FieldsSetter._set_field_2 - __fbthrift_inst._setters[__cstring_view("tiny")] = __MinPaddingWithCustomType_FieldsSetter._set_field_3 + __fbthrift_inst._setters[__cstring_view("medium")] = __MinPaddingWithCustomType_FieldsSetter._set_field_2 + __fbthrift_inst._setters[__cstring_view("biggish")] = __MinPaddingWithCustomType_FieldsSetter._set_field_3 + __fbthrift_inst._setters[__cstring_view("tiny")] = __MinPaddingWithCustomType_FieldsSetter._set_field_4 return __fbthrift_inst cdef void set_field(__MinPaddingWithCustomType_FieldsSetter self, const char* name, object value) except *: @@ -506,19 +507,29 @@ cdef class __MinPaddingWithCustomType_FieldsSetter(__StructFieldsSetter): deref(self._struct_cpp_obj).big_ref().assign(_fbthrift_value) cdef void _set_field_2(self, _fbthrift_value) except *: - # for field biggish + # for field medium if _fbthrift_value is None: __reset_field[_apache_thrift_fixtures_types_module_types.cMinPaddingWithCustomType](deref(self._struct_cpp_obj), 2) return + if not isinstance(_fbthrift_value, int): + raise TypeError(f'medium is not a { int !r}.') + _fbthrift_value = _fbthrift_value + deref(self._struct_cpp_obj).medium_ref().assign(_fbthrift_value) + + cdef void _set_field_3(self, _fbthrift_value) except *: + # for field biggish + if _fbthrift_value is None: + __reset_field[_apache_thrift_fixtures_types_module_types.cMinPaddingWithCustomType](deref(self._struct_cpp_obj), 3) + return if not isinstance(_fbthrift_value, int): raise TypeError(f'biggish is not a { int !r}.') _fbthrift_value = _fbthrift_value deref(self._struct_cpp_obj).biggish_ref().assign(_fbthrift_value) - cdef void _set_field_3(self, _fbthrift_value) except *: + cdef void _set_field_4(self, _fbthrift_value) except *: # for field tiny if _fbthrift_value is None: - __reset_field[_apache_thrift_fixtures_types_module_types.cMinPaddingWithCustomType](deref(self._struct_cpp_obj), 3) + __reset_field[_apache_thrift_fixtures_types_module_types.cMinPaddingWithCustomType](deref(self._struct_cpp_obj), 4) return if not isinstance(_fbthrift_value, int): raise TypeError(f'tiny is not a { int !r}.') diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_reflection.py b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_reflection.py index 5e823114343918..b8b769e8aabd6e 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_reflection.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types_reflection.py @@ -487,6 +487,19 @@ def get_reflection__MinPaddingWithCustomType() -> __StructSpec: }, ), ) + spec.add_field( + __FieldSpec._fbthrift_create( + id=3, + name="medium", + py_name="medium", + type=int, + kind=__NumberType.I16, + qualifier=__Qualifier.UNQUALIFIED, + default=None, + annotations={ + }, + ), + ) spec.add_field( __FieldSpec._fbthrift_create( id=4, diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/module/types.h b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/module/types.h index ec91b38f14c4d6..d29fdf7d6fd6f4 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/module/types.h +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/py3/gen-py3/module/types.h @@ -184,9 +184,12 @@ inline void reset_field<::apache::thrift::fixtures::types::MinPaddingWithCustomT obj.big_ref().copy_from(default_inst<::apache::thrift::fixtures::types::MinPaddingWithCustomType>().big_ref()); return; case 2: - obj.biggish_ref().copy_from(default_inst<::apache::thrift::fixtures::types::MinPaddingWithCustomType>().biggish_ref()); + obj.medium_ref().copy_from(default_inst<::apache::thrift::fixtures::types::MinPaddingWithCustomType>().medium_ref()); return; case 3: + obj.biggish_ref().copy_from(default_inst<::apache::thrift::fixtures::types::MinPaddingWithCustomType>().biggish_ref()); + return; + case 4: obj.tiny_ref().copy_from(default_inst<::apache::thrift::fixtures::types::MinPaddingWithCustomType>().tiny_ref()); return; }