From ec7e8810cd696baeeb6629f05e967c17ae18106e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 05:35:38 +0000 Subject: [PATCH 1/4] Initial plan From ac1ffd7dbe49c1fb358088156aba5f86f63a9a8c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 05:39:05 +0000 Subject: [PATCH 2/4] fix(http-client-python): use List alias in paging return type annotation when operation is named `list` Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4cebf863-2c8f-48d2-89f0-ff2253256997 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../python-fix-paging-list-typing-2026-4-28-5-36-18.md | 7 +++++++ .../generator/pygen/codegen/models/response.py | 1 + 2 files changed, 8 insertions(+) create mode 100644 .chronus/changes/python-fix-paging-list-typing-2026-4-28-5-36-18.md diff --git a/.chronus/changes/python-fix-paging-list-typing-2026-4-28-5-36-18.md b/.chronus/changes/python-fix-paging-list-typing-2026-4-28-5-36-18.md new file mode 100644 index 00000000000..839d6545130 --- /dev/null +++ b/.chronus/changes/python-fix-paging-list-typing-2026-4-28-5-36-18.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Fix typing in generated paging operations when an operation is named `list` and the page item is a collection type. The return type annotation now correctly uses the `List` alias (e.g. `AsyncItemPaged[List[str]]`) instead of the built-in `list` (which would shadow the operation name) to stay consistent with other annotations in the same file. diff --git a/packages/http-client-python/generator/pygen/codegen/models/response.py b/packages/http-client-python/generator/pygen/codegen/models/response.py index d93d46bd897..da1c80b308f 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/response.py +++ b/packages/http-client-python/generator/pygen/codegen/models/response.py @@ -181,6 +181,7 @@ def get_pager(self, async_mode: bool) -> str: def type_annotation(self, **kwargs: Any) -> str: iterable = "AsyncItemPaged" if kwargs["async_mode"] else "ItemPaged" + kwargs["is_operation_file"] = True return f"{iterable}[{self.item_type.type_annotation(**kwargs)}]" def docstring_text(self, **kwargs: Any) -> str: From 0f3a0cce399bfd174896a53ceacf61d6f01f645f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 11 May 2026 09:33:54 +0000 Subject: [PATCH 3/4] preserve forward-reference quoting for model item types in PagingResponse Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1ccb87cf-7ba3-467c-b22d-40aa4dd56b48 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../generator/pygen/codegen/models/response.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/models/response.py b/packages/http-client-python/generator/pygen/codegen/models/response.py index da1c80b308f..5e8634a916e 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/response.py +++ b/packages/http-client-python/generator/pygen/codegen/models/response.py @@ -11,7 +11,7 @@ from .primitive_types import BinaryType, BinaryIteratorType, ByteArraySchema from .dictionary_type import DictionaryType from .list_type import ListType -from .model_type import ModelType +from .model_type import ModelType, GeneratedModelType from .combined_type import CombinedType if TYPE_CHECKING: @@ -181,8 +181,14 @@ def get_pager(self, async_mode: bool) -> str: def type_annotation(self, **kwargs: Any) -> str: iterable = "AsyncItemPaged" if kwargs["async_mode"] else "ItemPaged" - kwargs["is_operation_file"] = True - return f"{iterable}[{self.item_type.type_annotation(**kwargs)}]" + item_kwargs = dict(kwargs) + # Set is_operation_file=True so nested list types use the `List` alias + # when there is an operation named `list`. Skip for generated model + # types to preserve historical forward-reference quoting of model + # types in paging responses. + if not isinstance(self.item_type, GeneratedModelType): + item_kwargs["is_operation_file"] = True + return f"{iterable}[{self.item_type.type_annotation(**item_kwargs)}]" def docstring_text(self, **kwargs: Any) -> str: base_description = "An iterator like instance of " From 051b65eedf54d92d7cc2af6a8aecce0181bf1a45 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 12 May 2026 03:47:14 +0000 Subject: [PATCH 4/4] handle ListType page items without propagating is_operation_file to nested model element types Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/0765c171-f668-4f09-8a6e-84b04cc0ca76 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../pygen/codegen/models/response.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/models/response.py b/packages/http-client-python/generator/pygen/codegen/models/response.py index 5e8634a916e..d37986146fd 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/response.py +++ b/packages/http-client-python/generator/pygen/codegen/models/response.py @@ -11,7 +11,7 @@ from .primitive_types import BinaryType, BinaryIteratorType, ByteArraySchema from .dictionary_type import DictionaryType from .list_type import ListType -from .model_type import ModelType, GeneratedModelType +from .model_type import ModelType from .combined_type import CombinedType if TYPE_CHECKING: @@ -181,14 +181,21 @@ def get_pager(self, async_mode: bool) -> str: def type_annotation(self, **kwargs: Any) -> str: iterable = "AsyncItemPaged" if kwargs["async_mode"] else "ItemPaged" - item_kwargs = dict(kwargs) - # Set is_operation_file=True so nested list types use the `List` alias - # when there is an operation named `list`. Skip for generated model - # types to preserve historical forward-reference quoting of model - # types in paging responses. - if not isinstance(self.item_type, GeneratedModelType): - item_kwargs["is_operation_file"] = True - return f"{iterable}[{self.item_type.type_annotation(**item_kwargs)}]" + return f"{iterable}[{self._item_type_annotation(**kwargs)}]" + + def _item_type_annotation(self, **kwargs: Any) -> str: + # When the page item is a ListType, render the outer `List`/`list` + # wrapper here using the operation-file alias decision so a list page + # item rendered inside an operation file named `list` uses the `List` + # alias (avoiding the built-in `list` shadowed by `List = list`). + # Recurse into the element type without is_operation_file so nested + # generated model types keep their forward-reference quoting + # (e.g. ItemPaged[List["_models.Product"]]). + if isinstance(self.item_type, ListType): + use_list_import = self.code_model.has_operation_named_list + list_type = "List" if use_list_import else "list" + return f"{list_type}[{self.item_type.element_type.type_annotation(**kwargs)}]" + return self.item_type.type_annotation(**kwargs) def docstring_text(self, **kwargs: Any) -> str: base_description = "An iterator like instance of "