Skip to content

Commit f3be83c

Browse files
author
iscai-msft
committed
fix pylint and pyright in generated code
1 parent f5f9300 commit f3be83c

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

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

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,17 @@ def imports(self, **kwargs: Any) -> FileImport:
328328
alias="_Model",
329329
)
330330
elif serialize_namespace_type == NamespaceType.TYPES_FILE:
331-
# In types.py, import model names directly to avoid pyright
332-
# "variable not allowed in type expression" errors with dotted forward refs
333-
file_import.add_submodule_import(
334-
f"{relative_path}models" if relative_path != "." else ".models",
335-
self.name,
336-
ImportType.LOCAL,
337-
typing_section=TypingSection.TYPING,
338-
)
331+
# 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):
336+
file_import.add_submodule_import(
337+
f"{relative_path}models" if relative_path != "." else ".models",
338+
self.name,
339+
ImportType.LOCAL,
340+
typing_section=TypingSection.TYPING,
341+
)
339342
elif serialize_namespace_type == NamespaceType.UNIONS_FILE or (
340343
serialize_namespace_type == NamespaceType.MODEL and called_by_property
341344
):

0 commit comments

Comments
 (0)