Skip to content

Commit f77576c

Browse files
iscai-msftCopilot
andcommitted
fix: resolve CI failures in type checking, lint, and mock API tests
- Add 'List' import to ListType.imports() when property/operation named 'list' exists (fixes NameError in special-words types.py) - Use has_non_json_models() for has_models in ModelInitSerializer to avoid generating 'from . import _models' when _models.py doesn't exist - Add pylint disable=unused-import to 'from . import types' in init template Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1ff2c23 commit f77576c

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# --------------------------------------------------------------------------
66
from typing import Any, Optional, Union, TYPE_CHECKING
77
from .base import BaseType
8-
from .imports import FileImport
8+
from .imports import FileImport, ImportType
99

1010
if TYPE_CHECKING:
1111
from .code_model import CodeModel
@@ -136,6 +136,12 @@ def from_yaml(cls, yaml_data: dict[str, Any], code_model: "CodeModel") -> "ListT
136136
def imports(self, **kwargs: Any) -> FileImport:
137137
file_import = FileImport(self.code_model)
138138
file_import.merge(self.element_type.imports(**kwargs))
139+
is_operation_file = kwargs.get("is_operation_file", False)
140+
use_list_import = (self.code_model.has_operation_named_list and is_operation_file) or (
141+
self.code_model.has_property_named_list and not is_operation_file
142+
)
143+
if use_list_import:
144+
file_import.add_submodule_import("typing", "List", ImportType.STDLIB)
139145
return file_import
140146

141147
@property

packages/http-client-python/generator/pygen/codegen/serializers/model_init_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def serialize(self) -> str:
3232
", ".join(model_enum_name_intersection)
3333
)
3434
)
35-
has_models = self.models
35+
has_models = self.code_model.has_non_json_models(self.models)
3636
has_enums = self.enums
3737
template = self.env.get_template("model_init.py.jinja2")
3838
return template.render(

packages/http-client-python/generator/pygen/codegen/templates/init.py.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from .{{ client.filename }} import {{ client.name }} # type: ignore
1010
{% endfor %}
1111
{% endif %}
1212
{% if has_types %}
13-
from . import types # type: ignore
13+
from . import types # type: ignore # pylint: disable=unused-import
1414
{% endif %}
1515
{% if not async_mode and code_model.options.get("package-version") %}
1616
from {{ code_model.get_relative_import_path(serialize_namespace, module_name="_version") }} import VERSION

0 commit comments

Comments
 (0)