-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
"TypeError: TypedDict does not support instance and class checks" for TypedDict field #1430
Comments
I think I think you're right, though, and it probably is best to raise an explicit error when |
I confirm |
There's no logic for validating We should either support them fully or raise a sensible exception explaining that they don't work. This is an issue about raising a better error, #760 is about supporting them fully. |
I'm aware that no logic validation is currently performed by pydantic and it is fine with me.
There is also the option of treating them as v1.4 behaved like this:
|
Actually TypedDict does contain validation instructions
So technically Pydantic should be able to validate dictionaries that are type hinted with |
Yes, it's possible, now someone just needs to go and implement the feature. 😄 |
I currently have a working solution for this which does validation based on the TypedDict annotations as suggested. I'm currently writing test cases and will post an update when I've got full coverage. |
My solution is here, but there are parts of it that I think could probably be done better:
Would appreciate feedback/suggestions before trying to make a pull request. Edit: Forgot to mention, all tests are passing and all lines that I added should be covered. |
Bug
Models with TypedDict fields currently result in an error when they are instantiated, due to the fact that TypedDict does not support isinstance/issubclass checks.
Previously, models could have TypedDict fields without any problems. This error seems to have been introduced in commit #1266.
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:The text was updated successfully, but these errors were encountered: