-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Star operator gets confused when the type has multiple generics #11138
Comments
@KotlinIsland this line does not seem to be correct: from typing import Iterator, Generic, TypeVar
T = TypeVar("T")
T2 = TypeVar("T2")
class A(Iterator[T2], Generic[T, T2]):
...
a: A[int, Iterator[int]] = A()
reveal_type((*a,))
reveal_type([*a])
b: list[int] = [*a] It works: https://mypy-play.net/?mypy=latest&python=3.10&gist=e9ba2aada4295a07d24c5508eadfb5f0 |
@sobolevn actually it should be a |
I think this is clearer: https://mypy-play.net/?mypy=latest&python=3.10&gist=e7a3eb908190fd06c04032459aae0d70 |
from typing import Generic, TypeVar
T = TypeVar("T")
T2 = TypeVar("T2")
class A(Iterator[T2], Generic[T, T2]):
...
a: A[str, int]
reveal_type((*a,)) # note: Revealed type is "builtins.tuple[builtins.str*]"
b: list[int] = [*a] # error: List item 0 has incompatible type "A[str, int]"; expected "int" |
@KotlinIsland's latest gist does look pretty buggy. For |
I like this example of the bug: from typing import Generic, Iterator, TypeVar
T = TypeVar("T")
U = TypeVar("U")
class X(Iterator[U], Generic[T, U]):
pass
x: X[str, int]
reveal_type(list(x)) # N: Revealed type is "builtins.list[builtins.int*]"
reveal_type([*x]) # N: Revealed type is "builtins.list[builtins.str*]" |
Oh, I see. Will try to fix it tomorrow 👍 |
Yeap, solved using Lines 168 to 173 in b3ff2a6
But, I need changes from #11151 to make it work correctly. Right now it is blocked. |
Nice catch! I figured we were assuming somewhere that the first generic arg was for Iterable, but couldn't find the right place in the code. |
Bug Report
When a type has multiple generics and is an iterable, the star operator results in the wrong type
To Reproduce
(Write your steps here:)
Expected Behavior
(Write what you thought would happen.)
Actual Behavior
(Write what happened.)
Your Environment
mypy.ini
(and other config files): naThe text was updated successfully, but these errors were encountered: