Skip to content

fix(http-client-python): clear mypy [no-any-return] in generated _validation.py#10571

Open
l0lawrence wants to merge 2 commits into
microsoft:mainfrom
l0lawrence:fix/python-validation-mypy-any-return
Open

fix(http-client-python): clear mypy [no-any-return] in generated _validation.py#10571
l0lawrence wants to merge 2 commits into
microsoft:mainfrom
l0lawrence:fix/python-validation-mypy-any-return

Conversation

@l0lawrence
Copy link
Copy Markdown
Member

Problem

Generated SDK code produces a mypy error in _validation.py:

```n_validation.py:26: error: Returning Any from function declared to return int [no-any-return]


The offending line is `return api_versions_list.index(value)` inside `_index_with_default`. Because `api_versions_list` is pulled from untyped `**kwargs` via `kwargs.pop(...)`, mypy infers it as `Any`, so `.index(value)` returns `Any` from a function declared `-> int`.

## Fix

Type-annotate the local `api_versions_list` as `list[str]` in the `validation.py.jinja2` template (Python 3.10+ is already the minimum supported version). This is sufficient to clear the `[no-any-return]` error in the generated `_validation.py`.

## Verification

Reproduced the original mypy error against the unmodified template body and confirmed it is cleared after the change with `mypy --python-version 3.10 --strict`.

Reported against `azure/search/documents/_validation.py`.

…-return] in generated _validation.py

Co-authored-by: Copilot <223556219+Copilot@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 30, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

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

commit: be42d11

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

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

Fix mypy [no-any-return] error in generated _validation.py by typing api_versions_list as list[str] so _index_with_default returns int rather than Any.

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Apr 30, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label May 30, 2026
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

Hi @@l0lawrence. Your PR has had no update for 30 days and it is marked as a stale PR. If it is not updated within 30 days, the PR will automatically be closed. If you want to refresh the PR, please remove the stale label.

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 stale Mark a PR that hasn't been recently updated and will be closed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants