-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Can't pass a value of type Union[str, bytes] to a generic function typed with AnyStr #1533
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
Comments
Yeah, it would be nice if the example would work. Generally substituting The reason why can't substitute a union is a little subtle. First, consider this example:
Now the call should be rejected, since Here is another example:
The latter example is similar but doesn't use generics. Here we could type check the call Substituting a union type might be safe if |
We do already perform this kind of separate type checking of each case when type checking a method call on a union, so it does seem natural to extend that to function calls as @JukkaL described. Another place this would come up is in calls to overloaded functions. |
Uh oh!
There was an error while loading. Please reload this page.
Repro:
We get an error on the last line:
I would have expected that it would just deduce that y is also a Union[str, bytes].
(UPDATE: shortened the repro.)
The text was updated successfully, but these errors were encountered: