-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Taking a slice that contains unions produces Any #4286
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
Because after you unpacked, there are three independent variables |
This however works fine:
|
And this is a bug! def c() -> typing.Union[typing.Tuple[str, str, str],
typing.Tuple[typing.List[str], typing.List[str], typing.List[str]]]:
x, y, z = a()[:]
reveal_type(x) # Revealed type is Any
return x, y, z I think however this is not an independent problem, but a manifestation of a known problem of interactions between unions and overloads. @JukkaL what do you think? |
Looks like there are two problems. First, the fallback of the tuple types seems to be |
There is an issue for this already, and I am going to fix it soon (I am going to go with
I think with the first one fixed, this seems to be not urgent. |
Yes, the first issue seems more urgent. I'll create a new issue to track second issue. |
Actually we can use this issue to track the second issues. Here's a simplified example: from typing import Union, Tuple
t: Union[Tuple[int, float], Tuple[str, bool]]
reveal_type(t[0]) # Revealed type is 'Any'
reveal_type(t[:]) # Revealed type is 'builtins.tuple[Any]' The expected revealed types are |
Your tuple fallback PR causes a bunch of errors internally because fallback is now |
Uh oh!
There was an error while loading. Please reload this page.
Result:
error: Incompatible return value type (got "Tuple[Union[str, List[str]], Union[str, List[str]], Union[str, List[str]]]", expected "Union[Tuple[str, str, str], Tuple[List[str], List[str], List[str]]]")
Why?
The text was updated successfully, but these errors were encountered: