mypy doesn't understand partial unpacking with star arguments
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
While working on https://github.com/qutebrowser/qutebrowser/pull/5317 I think I may have found a bug in mypy. The following code looks correct, and runs fine on my machine.
To Reproduce
- Save the following code to file
/tmp/reproducer.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: fenc=utf-8:et:ts=4:sts=4:sw=4:fdm=marker
from typing import Optional, Sequence, Mapping
import collections
class ModuleInfo:
def __init__(
self,
name: str,
version_attributes: Sequence[str],
min_version: Optional[str] = None
):
self.name = name
self._version_attributes = version_attributes
self.min_version = min_version
MODULE_INFO: Mapping[str, ModuleInfo] = collections.OrderedDict([
(name, ModuleInfo(name, *args))
for (name, *args) in
[
('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', []),
]
])
- Run
mypy /tmp/reproducer.py.
Expected Behavior
There should be no type errors.
Actual Behavior
The output of the command in step 2 returns:
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 - Python version used:
Python 3.8.6 - Operating system and version: Gentoo Linux
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem Beispiel /tmp/reproducer.py und führe mypy /tmp/reproducer.py mit den angegebenen Python- und mypy-Versionen aus. Verfolge, wie der Typprüfer das Entpacken eines Tupels mit Sternchen und den Konstruktoraufruf verarbeitet, und aktualisiere anschließend das Verhalten so, dass der Reproducer keine Typfehler meldet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100