From 48e8f708479ec834b841b8dbebc6d4cdc9bc2fb6 Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Fri, 25 Jul 2025 01:21:35 +0000 Subject: [PATCH 1/3] [Python] Ensure necessary model imports Internal models still get `__init__` overloads and still need the necessary imports. This changes the conditional check to use `need_init` which is more appropriate. This fixes the cases where all models are internal and `Mapping` and `overload` imports are missing in the generated `_models.py` file. Signed-off-by: Paul Van Eck --- .../generator/pygen/codegen/serializers/model_serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py index 4f2fd9c196e..350b0b4c68c 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py @@ -266,7 +266,7 @@ def imports(self) -> FileImport: ) if model.is_polymorphic: file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) - if not model.internal and self.init_line(model): + if self.need_init(model): file_import.add_submodule_import("typing", "overload", ImportType.STDLIB) file_import.add_submodule_import("typing", "Mapping", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) From 6b9acf44f58937129390c59e5f504e506ea26294 Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Fri, 25 Jul 2025 10:38:10 -0700 Subject: [PATCH 2/3] Create typespec-internal-model-imports-2025-6-25-1-29-21.md --- .../typespec-internal-model-imports-2025-6-25-1-29-21.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md diff --git a/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md b/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md new file mode 100644 index 00000000000..df8a1c6e8e1 --- /dev/null +++ b/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +[Python] Ensure necessary typing imports for internal models From 4648d81fce5f60c26ee279195298bf3d750871ec Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Fri, 25 Jul 2025 11:18:55 -0700 Subject: [PATCH 3/3] Update typespec-internal-model-imports-2025-6-25-1-29-21.md --- .../typespec-internal-model-imports-2025-6-25-1-29-21.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md b/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md index df8a1c6e8e1..062027577cd 100644 --- a/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md +++ b/.chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md @@ -5,4 +5,4 @@ packages: - "@typespec/http-client-python" --- -[Python] Ensure necessary typing imports for internal models +Ensure necessary typing imports for internal models