You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Star operator gets confused when the type has multiple generics #11138
@KotlinIsland this line does not seem to be correct: b: list[list[int]] = [*a]. That's exactly what error: List item 0 has incompatible type "A[int, Iterator[int]]"; expected "List[int]" tells you about.
Here b should be list[int]:
@KotlinIsland's latest gist does look pretty buggy. For (*a,) it infers tuple[str, ...], which is wrong because a is an Iterator[Iterator[int]] instead.
Activity
sobolevn commentedon Sep 18, 2021
@KotlinIsland this line does not seem to be correct:
b: list[list[int]] = [*a]. That's exactly whaterror: List item 0 has incompatible type "A[int, Iterator[int]]"; expected "List[int]"tells you about.Here
bshould belist[int]:It works: https://mypy-play.net/?mypy=latest&python=3.10&gist=e9ba2aada4295a07d24c5508eadfb5f0
Similar to
reveal_type((*a,))which revealsRevealed type is "builtins.tuple[builtins.int*]"KotlinIsland commentedon Sep 19, 2021
@sobolevn actually it should be a
list[Iterator[int]]KotlinIsland commentedon Sep 19, 2021
I think this is clearer: https://mypy-play.net/?mypy=latest&python=3.10&gist=e7a3eb908190fd06c04032459aae0d70
KotlinIsland commentedon Sep 19, 2021
JelleZijlstra commentedon Sep 19, 2021
@KotlinIsland's latest gist does look pretty buggy. For
(*a,)it inferstuple[str, ...], which is wrong becauseais anIterator[Iterator[int]]instead.JelleZijlstra commentedon Sep 19, 2021
I like this example of the bug:
sobolevn commentedon Sep 20, 2021
Oh, I see. Will try to fix it tomorrow 👍
sobolevn commentedon Sep 20, 2021
Yeap, solved using
map_instance_to_supertype(actual_type, Iterable)here:mypy/mypy/argmap.py
Lines 168 to 173 in b3ff2a6
But, I need changes from #11151 to make it work correctly. Right now it is blocked.
@JelleZijlstra I would appreciate your review to get it merged! 🙏
JelleZijlstra commentedon Sep 20, 2021
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.