Skip to content

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

Merged
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
msyyc merged 6 commits into
mainfrom
copilot/fix-wrong-typing-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

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.

Copilot AI linked an issue Apr 28, 2026 that may be closed by this pull request
…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
Copilot AI requested a review from msyyc April 28, 2026 05:41
@msyyc msyyc marked this pull request as ready for review May 11, 2026 08:35
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 11, 2026

Open in StackBlitz

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

commit: fb15bab

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

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
Copy link
Copy Markdown
Collaborator

azure-sdk commented May 11, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Comment thread packages/http-client-python/generator/pygen/codegen/models/response.py Outdated
@msyyc msyyc marked this pull request as draft May 11, 2026 09:30
Copilot finished work on behalf of msyyc May 11, 2026 09:35
Copilot AI requested a review from msyyc May 11, 2026 09:35
…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>
Copilot finished work on behalf of msyyc May 12, 2026 03:48
@msyyc 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 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