diff --git a/third-party/thrift/src/thrift/compiler/generate/templates/python/types/types.mustache b/third-party/thrift/src/thrift/compiler/generate/templates/python/types/types.mustache index e944fdbbc626a..ec425f1fefd21 100644 --- a/third-party/thrift/src/thrift/compiler/generate/templates/python/types/types.mustache +++ b/third-party/thrift/src/thrift/compiler/generate/templates/python/types/types.mustache @@ -30,14 +30,12 @@ import {{program:base_library_package}}.mutable_exceptions as _fbthrift_python_m import {{program:base_library_package}}.mutable_typeinfos as _fbthrift_python_mutable_typeinfos {{/program:generate_mutable_types}} -{{^program:generate_mutable_types}} {{#program:include_namespaces}} {{#has_types?}} -import {{included_module_path}}.thrift_types +import {{included_module_path}}.{{> types/types_import_path}} {{/has_types?}} {{/program:include_namespaces}} -{{/program:generate_mutable_types}} {{#program:adapter_modules}} import {{module_path}} {{/program:adapter_modules}} diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/includes/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py b/third-party/thrift/src/thrift/compiler/test/fixtures/includes/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py index 1ad5a9e22d9b3..b41e479a6f84a 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/includes/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/includes/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py @@ -18,6 +18,8 @@ import thrift.python.mutable_typeinfos as _fbthrift_python_mutable_typeinfos +import includes.thrift_mutable_types + class MyStruct(metaclass=_fbthrift_python_mutable_types.MutableStructMeta): _fbthrift_SPEC = ( diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/inject_metadata_fields/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py b/third-party/thrift/src/thrift/compiler/test/fixtures/inject_metadata_fields/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py index c98c98cc2dd5d..695d910e45601 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/inject_metadata_fields/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/inject_metadata_fields/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py @@ -18,6 +18,8 @@ import thrift.python.mutable_typeinfos as _fbthrift_python_mutable_typeinfos +import foo.thrift_mutable_types + class Fields(metaclass=_fbthrift_python_mutable_types.MutableStructMeta): _fbthrift_SPEC = ( diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/interactions/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/interactions/module/thrift_mutable_types.py b/third-party/thrift/src/thrift/compiler/test/fixtures/interactions/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/interactions/module/thrift_mutable_types.py index af736ac02bed2..a84730b507074 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/interactions/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/interactions/module/thrift_mutable_types.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/interactions/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/interactions/module/thrift_mutable_types.py @@ -18,6 +18,8 @@ import thrift.python.mutable_typeinfos as _fbthrift_python_mutable_typeinfos +import test.fixtures.another_interactions.shared.thrift_mutable_types + class CustomException(metaclass=_fbthrift_python_mutable_exceptions.MutableGeneratedErrorMeta): _fbthrift_SPEC = ( diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/python_capi/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/python_capi/module/thrift_mutable_types.py b/third-party/thrift/src/thrift/compiler/test/fixtures/python_capi/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/python_capi/module/thrift_mutable_types.py index ad310b3bf1173..ab5f3d20422ff 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/python_capi/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/python_capi/module/thrift_mutable_types.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/python_capi/out/python_experimental_generate_mutable_types/gen-python/test/fixtures/python_capi/module/thrift_mutable_types.py @@ -18,6 +18,14 @@ import thrift.python.mutable_typeinfos as _fbthrift_python_mutable_typeinfos +import apache.thrift.type.id.thrift_mutable_types + +import apache.thrift.type.schema.thrift_mutable_types + +import test.fixtures.python_capi.serialized_dep.thrift_mutable_types + +import test.fixtures.python_capi.thrift_dep.thrift_mutable_types + class MyStruct(metaclass=_fbthrift_python_mutable_types.MutableStructMeta): _fbthrift_SPEC = ( diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/service-schema/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py b/third-party/thrift/src/thrift/compiler/test/fixtures/service-schema/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py index 71999253edf21..3ce7fec2f0d4b 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/service-schema/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/service-schema/out/python_experimental_generate_mutable_types/gen-python/module/thrift_mutable_types.py @@ -18,6 +18,8 @@ import thrift.python.mutable_typeinfos as _fbthrift_python_mutable_typeinfos +import include.thrift_mutable_types + class CustomException(metaclass=_fbthrift_python_mutable_exceptions.MutableGeneratedErrorMeta): _fbthrift_SPEC = ( diff --git a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/python_experimental_generate_mutable_types/gen-python/apache/thrift/fixtures/types/module/thrift_mutable_types.py b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/python_experimental_generate_mutable_types/gen-python/apache/thrift/fixtures/types/module/thrift_mutable_types.py index f46148e3efc5f..15361021a7272 100644 --- a/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/python_experimental_generate_mutable_types/gen-python/apache/thrift/fixtures/types/module/thrift_mutable_types.py +++ b/third-party/thrift/src/thrift/compiler/test/fixtures/types/out/python_experimental_generate_mutable_types/gen-python/apache/thrift/fixtures/types/module/thrift_mutable_types.py @@ -18,6 +18,8 @@ import thrift.python.mutable_typeinfos as _fbthrift_python_mutable_typeinfos +import apache.thrift.fixtures.types.included.thrift_mutable_types + class empty_struct(metaclass=_fbthrift_python_mutable_types.MutableStructMeta): _fbthrift_SPEC = ( diff --git a/third-party/thrift/src/thrift/test/thrift-python/included.thrift b/third-party/thrift/src/thrift/test/thrift-python/included.thrift new file mode 100644 index 0000000000000..16118eba3ed9c --- /dev/null +++ b/third-party/thrift/src/thrift/test/thrift-python/included.thrift @@ -0,0 +1,22 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace py3 thrift.test.thrift_python + +union TestUnion { + 1: i32 i32_field; + 2: string string_field; +} diff --git a/third-party/thrift/src/thrift/test/thrift-python/struct_test.thrift b/third-party/thrift/src/thrift/test/thrift-python/struct_test.thrift index f5d4fd58cf24a..161e6e78a745f 100644 --- a/third-party/thrift/src/thrift/test/thrift-python/struct_test.thrift +++ b/third-party/thrift/src/thrift/test/thrift-python/struct_test.thrift @@ -15,6 +15,7 @@ */ include "thrift/annotation/python.thrift" +include "thrift/test/thrift-python/included.thrift" namespace py3 thrift.test.thrift_python @@ -160,6 +161,7 @@ union TestUnion { struct TestStructWithUnionField { 1: i32 i32_field; 2: TestUnion union_field; + 3: included.TestUnion union_field_from_included; } exception TestExceptionAllThriftPrimitiveTypes {