Skip to content

Commit df17af5

Browse files
iscai-msftCopilot
andcommitted
fix: skip model imports in types.py regardless of namespace
All TypedDict models are defined in the same types.py file, so cross- namespace model imports also cause redefinition errors. Remove the same_namespace check so any model that will be a TypedDict is never imported from its models module. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e6b1b52 commit df17af5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • packages/http-client-python/generator/pygen/codegen/models

packages/http-client-python/generator/pygen/codegen/models/model_type.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ def imports(self, **kwargs: Any) -> FileImport:
329329
)
330330
elif serialize_namespace_type == NamespaceType.TYPES_FILE:
331331
# Don't import models that will be defined as TypedDicts in the same types.py file.
332-
# The forward reference string will resolve to the local TypedDict class definition.
333-
same_namespace = relative_path == "."
334-
will_be_local_typeddict = self.base != "json" and not self.discriminated_subtypes
335-
if not (same_namespace and will_be_local_typeddict):
332+
# All non-json, non-discriminated-base models generate TypedDicts in types.py,
333+
# regardless of namespace, so the bare forward reference resolves locally.
334+
will_be_typeddict = self.base != "json" and not self.discriminated_subtypes
335+
if not will_be_typeddict:
336336
file_import.add_submodule_import(
337337
f"{relative_path}models" if relative_path != "." else ".models",
338338
self.name,

0 commit comments

Comments
 (0)