-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Structuring a non-dict type as TypedDict raises AttributeError #615
Comments
Hm, agreed. Let me get this for the next version. |
I think I got this on main. Can you give it a try and let me know? |
Thanks! I will try it on my real example and let you know. Regarding the fix, did you intentionally avoid an |
Hm, interesting. My thinking is this: catching an AttributeError adds essentially no overhead, and a separate isinstance check would be felt, especially on small dicts. It's also a little unclear what to check against ( Let me see what happens if a list is passed in when I get to a computer. |
I think you're right, the error message kind of sucks when lists are involved. Here's a new try: #617 |
Description
I am structuring a TypedDict type. The input is arbitrary (from JSON), and I want to offload the validation to cattrs.
The problem is, if the input is not a
dict
(in my case, not a JSON object), cattrs raises anAttributeError
instead of the expectedcattrs.errors.ClassValidationError
.I would like to avoid catching
AttributeError
or adding my own pre-checks.What I Did
Running the script above results in:
The text was updated successfully, but these errors were encountered: