-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Type checking fails when registering a structure hook on a Union #105
Comments
Looks like a mypy bug to me, feel free to go over to their issue tracker and log this. For example,
|
I went over to the python/typing gitter and got some feedback from oremanj that this is correct. Unions describe types but don't meet the We also can't express "a Type or a Union of Types" directly; you can't construct a type hint that accepts any old Union because the type of a Union[...] isn't a Union, it's just Do you buy that? I could go ahead and open an issue against mypy to collect some more feedback, especially on the second point -- my guess is that mypy will be reluctant to make a change but we can explain the use case. |
Yeah, I buy that a subset of the type system doesn't fulfil the This means we can't annotate this method properly, though. It would be nice to have a type to express a valid type hint though. In any case, looks like this is a missing feature instead of a bug in Mypy. I'll take a PR changing this type annotation to If you feel like it, feel free to make an issue over at Mypy explaining the situation. |
Fixed on master. |
Description
After upgrading from cattrs 1.0, mypy has started rejecting Union types as the type argument to
Converter.register_structure_hook
.I think the docs at https://cattrs.readthedocs.io/en/latest/structuring.html#manual-disambiguation say that this is the supported way to structure a union type. It executes fine, but mypy rejects it.
What I Did
The text was updated successfully, but these errors were encountered: