Repository navigation
Fix mypy error in common.ai decision helper with pydantic-ai 2.46 - #73652
Merged
Merged
Conversation
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.
Andrushika
marked this pull request as ready for review
September 24, 2026 09:30
Andrushika
requested review from
Lee-W,
ashb,
gopidesupavan and
kaxil
as code owners
September 24, 2026 09:30
potiuk
approved these changes
Sep 24, 2026
Member
|
Also thanks! |
potiuk
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
_choice_types()inproviders/common/ai/.../utils/decision.pyimportsChoiceandChoicesfrom pydantic-ai on first use, and falls back toNoneon 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 theNonefallback. 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
Nonefallback to the module globals inexcept, and copy the imported types inelse, 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 onproviders/common/aiin 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?
Generated-by: Claude Code (Opus 5.5) following the guidelines