-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
mypy doesn't understand partial unpacking with star arguments #9706
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
Labels
bug
mypy got something wrong
Comments
This happens because your iterable type is not infered correctly: from typing import Optional, Sequence, Mapping, Tuple, Union
items = [
('sip', ['SIP_VERSION_STR']),
('colorama', ['VERSION', '__version__']),
('pypeg2', ['__version__']),
('jinja2', ['__version__']),
('pygments', ['__version__']),
('yaml', ['__version__']),
('adblock', ['__version__'], "0.3.2"),
('cssutils', ['__version__']),
('attr', ['__version__']),
('PyQt5.QtWebEngineWidgets', []),
('PyQt5.QtWebEngine', ['PYQT_WEBENGINE_VERSION_STR']),
('PyQt5.QtWebKitWidgets', []),
]
reveal_type(items)
# note: Revealed type is 'builtins.list[builtins.tuple*[typing.Sequence[builtins.str]]]' And: from typing import Optional, Sequence, Mapping, Tuple, Union
items: Sequence[Union[
Tuple[str, Sequence[str]],
Tuple[str, Sequence[str], str],
]] = [
('sip', ['SIP_VERSION_STR']),
('colorama', ['VERSION', '__version__']),
('pypeg2', ['__version__']),
('jinja2', ['__version__']),
('pygments', ['__version__']),
('yaml', ['__version__']),
('adblock', ['__version__'], "0.3.2"),
('cssutils', ['__version__']),
('attr', ['__version__']),
('PyQt5.QtWebEngineWidgets', []),
('PyQt5.QtWebEngine', ['PYQT_WEBENGINE_VERSION_STR']),
('PyQt5.QtWebKitWidgets', []),
]
reveal_type(items)
# note: Revealed type is 'typing.Sequence[Union[Tuple[builtins.str, typing.Sequence[builtins.str]], Tuple[builtins.str, typing.Sequence[builtins.str], builtins.str]]]' |
When I try the following MODULE_INFO: Mapping[str, ModuleInfo] = collections.OrderedDict([
(name, ModuleInfo(name, *args))
for (name, *args) in cast(
Sequence[Union[Tuple[str, Sequence[str]], Tuple[str, Sequence[str], str]]],
[
('sip', ['SIP_VERSION_STR']),
('colorama', ['VERSION', '__version__']),
('pypeg2', ['__version__']),
('jinja2', ['__version__']),
('pygments', ['__version__']),
('yaml', ['__version__']),
('adblock', ['__version__'], "0.3.2"),
('cssutils', ['__version__']),
('attr', ['__version__']),
('PyQt5.QtWebEngineWidgets', []),
('PyQt5.QtWebEngine', ['PYQT_WEBENGINE_VERSION_STR']),
('PyQt5.QtWebKitWidgets', []),
]
)
]) I still get the error
|
Ok, I followed all the way down to the rabbit hole. This happens because In contrast to from typing import Optional, Sequence, Mapping, Tuple, Union
items: Sequence[Union[
Tuple[str, Sequence[str]],
Tuple[str, Sequence[str], int],
]]
for a, *args in items:
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*]]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
While working on qutebrowser/qutebrowser#5317 I think I may have found a bug in mypy. The following code looks correct, and runs fine on my machine.
To Reproduce
/tmp/reproducer.py
mypy /tmp/reproducer.py
.Expected Behavior
There should be no type errors.
Actual Behavior
The output of the command in step 2 returns:
Your Environment
mypy 0.790
mypy /tmp/reproducer.py
mypy.ini
(and other config files): None, I thinkPython 3.8.6
The text was updated successfully, but these errors were encountered: