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.
Changes
The
pydantic.VERSION
variable is not a Literal expression, so mypy is unable to assert whether we're in an environment running on Pydantic V2 or V1. This results in mypy trying to follow both paths and failing with ano-redef
error, which is silenced by the# type: ignore
comment.This PR improves the code quality by removing the
# type: ignore
comment and adding aif TYPE_CHECKING
block that only imports the latest version (V2).This was the main intent of the PR. As a bonus, this also updates the
example
kwarg toexamples
, as it is expected for Pydantic V2.One line description for the changelog
Improved Pydantic V2 typechecking support.