Skip to content

Fix mypy error in common.ai decision helper with pydantic-ai 2.46 - #73652

Merged
potiuk merged 1 commit into
apache:mainfrom
Andrushika:fix-mypy-pydantic-ai-choice
Sep 24, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
Andrushika:fix-mypy-pydantic-ai-choice

Conversation

@Andrushika

Copy link
Copy Markdown
Contributor

Why

_choice_types() in providers/common/ai/.../utils/decision.py imports Choice and Choices from pydantic-ai on first use, and falls back to None on versions before 2.46.0. pydantic-ai-slim 2.46.0 adds both names, so mypy now types the imported aliases as those classes and rejects the None fallback. The CI environment upgrade in #73629 bumps pydantic-ai-slim to 2.46.0, and its providers mypy check fails with 3 errors on this line.

What

Assign the None fallback to the module globals in except, and copy the imported types in else, so runtime behaviour does not change. CI on this PR still uses 2.44.0 and passes with or without the change, so I checked with mypy on providers/common/ai in breeze: the old code fails on 2.46.0, and this change passes on both 2.44.0 and 2.46.0.

related: #73629


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

pydantic-ai-slim 2.46.0 exports Choice and Choices, so mypy now infers
the aliased import names as those types and rejects the None fallback
assigned to them when the import fails. The CI environment upgrade to
2.46.0 fails the providers mypy check on this line.
@potiuk

potiuk commented Sep 24, 2026

Copy link
Copy Markdown
Member

Also thanks!

@potiuk
potiuk merged commit 61d99c0 into apache:main Sep 24, 2026
131 of 136 checks passed
@Andrushika
Andrushika deleted the fix-mypy-pydantic-ai-choice branch September 26, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants