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
mypy doesn't understand partial unpacking with star arguments #9706
reproducer.py:19: error: List comprehension has incompatible type List[Tuple[Sequence[str], ModuleInfo]]; expected List[Tuple[str, ModuleInfo]]
reproducer.py:19: error: Argument 1 to "ModuleInfo" has incompatible type "Sequence[str]"; expected "str"
reproducer.py:19: error: Argument 2 to "ModuleInfo" has incompatible type "*List[Sequence[str]]"; expected "Optional[str]"
Found 3 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: mypy 0.790
Mypy command-line flags: mypy /tmp/reproducer.py
Mypy configuration options from mypy.ini (and other config files): None, I think
reproducer.py:19: error: Argument 2 to "ModuleInfo" has incompatible type "*List[Sequence[str]]"; expected "Optional[str]"
Found 1 error in 1 file (checked 1 source file)
Ok, I followed all the way down to the rabbit hole.
This happens because is_subtype_ignoring_tvars returns that str is a subtype of Sequence. And [Sequence[str], str] gets joined into Sequence[str]. This is happing in the check_multi_assignment_from_union method of Checker
In contrast to
fromtypingimportOptional, Sequence, Mapping, Tuple, Unionitems: Sequence[Union[
Tuple[str, Sequence[str]],
Tuple[str, Sequence[str], int],
]]
fora, *argsinitems:
reveal_type(a)
reveal_type(args)
# ex.py:25: note: Revealed type is 'builtins.str'# ex.py:26: note: Revealed type is 'Union[builtins.list[typing.Sequence*[builtins.str]], builtins.list[builtins.object*]]'
Activity
sobolevn commentedon Nov 6, 2020
This happens because your iterable type is not infered correctly:
And:
ArniDagur commentedon Nov 6, 2020
When I try the following
I still get the error
sobolevn commentedon Nov 6, 2020
Ok, I followed all the way down to the rabbit hole.
This happens because
is_subtype_ignoring_tvarsreturns thatstris a subtype ofSequence. And[Sequence[str], str]gets joined intoSequence[str]. This is happing in thecheck_multi_assignment_from_unionmethod ofCheckerIn contrast to