Skip to content

[python] Fix paging return type annotation using built-in list when operation is named list - #10525

Merged
Yuchao Yan (msyyc) merged 6 commits into
mainfrom
copilot/fix-wrong-typing-issue
May 12, 2026
Merged

[python] Fix paging return type annotation using built-in list when operation is named list#10525
Yuchao Yan (msyyc) merged 6 commits into
mainfrom
copilot/fix-wrong-typing-issue

Conversation

Copilot AI commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

To fix #10524

When a paging operation is named list and its page item is itself a collection, the generated Python code renders the return type with the built-in list, which is shadowed by the List = list alias the emitter inserts at the top of the operation file. This produces inconsistent typing such as AsyncItemPaged[list[str]] alongside cls: ClsType[List[List[str]]] in the same method.

Root cause

Response.type_annotation sets kwargs["is_operation_file"] = True before delegating to the inner type so that ListType.type_annotation emits the List alias. PagingResponse.type_annotation overrode this method but forwarded kwargs to self.item_type.type_annotation(**kwargs) without setting that flag, so the page item's list type fell back to the built-in list. The cls annotation went through the parent path and rendered correctly, hence the mismatch.

…ion 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>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Apr 28, 2026
Copilot AI changed the title [WIP] Fix wrong typing in generated Python SDK [python] Fix paging return type annotation using built-in list when operation is named list Apr 28, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@10525

commit: fb15bab

@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - fix ✏️

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.

@azure-sdk

Azure SDK Bot (azure-sdk) commented May 11, 2026

Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Comment thread packages/http-client-python/generator/pygen/codegen/models/response.py Outdated
…ested 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>
@msyyc
Yuchao Yan (msyyc) added this pull request to the merge queue May 12, 2026
Merged via the queue into main with commit baa59b2 May 12, 2026
41 checks passed
@msyyc
Yuchao Yan (msyyc) deleted the copilot/fix-wrong-typing-issue branch May 12, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python][bug] wrong typing

4 participants