New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable "pydantic.FieldValidationInfo" is not valid as a type #7667
Comments
Thanks @LachlanMarnham for reporting this 🙏 I couldn't reproduce the problem. Could you please share your:
|
Same problem here upon upgrading to Pydantic v2.4. The validators stays functional, but mypy complains with : My configuration :
And my
|
I am having the same issue, but with Pyright. Pydantic 2.4.1 Error is the same |
please replace you can import it by |
There was no indication in the patch notes that In previous patch notes this has been called out explicitly, and the assumption is it would be called out in the future. The |
Sorry @peterHoburg for that. It was actually because Allow access to field_name and data in all validators You can find it's documentation here |
Thanks for the reply! That makes complete sense. I opened a PR here to add a small note in the docs saying |
Apologies for any breakages. We did everything we could to avoid this being a breaking change (hence the deprecation warning and not just removal, putting it behind The core of the matter is that try as we might we may to avoid any sort of breaking changes with the breadth of usage Pydantic gets almost any change has the potential to break something for someone in some way. In this case we probably didn't consider the implications for type checkers. Luckily like Hasan said above the fix should be as simple as replacing an import. |
Hey guys thanks for the replies. After seeing the deprecation warning I was pretty sure the removal was intentional, mostly raised the issue because of the missing changelog notes and for others hitting the same problem who come to GitHub issues to find solutions. From my POV I'm happy for this to be closed now that #7670 has been merged. The Thanks again. |
Initial Checks
Description
There seems to be a breaking change in v2.4. When I run
mypy
against my code I see:This worked in
pydantic==2.3.0
(confirmed with downgrade).In the 2.3 version of the migration docs,
FieldValidationInfo
is the recommended way to type theinfo
parameter tofield_validator
s. However this has been removed from the 2.4 version of the migration docs.In v2.4, I can see this in
pydantic/__init__.py
:but this is missing from v2.3. Is this an intentional breaking change to a minor release? I can't see anything about it in the changelog.
Note: I think this is only broken in the
pydantic.mypy
plugin, becauseFieldValidationInfo
is importable, and it does have thefield_name
anddata
attributes whichmypy
thinks are missing.Possibly relates to #7617
Many thanks.
Example Code
Running
mypy file.py
with thepydantic.mypy
plugin enabled results in:The text was updated successfully, but these errors were encountered: