mypy doesn't understand partial unpacking with star arguments
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’esempio /tmp/reproducer.py ed esegui mypy /tmp/reproducer.py usando le versioni di Python e mypy indicate. Traccia il modo in cui il verificatore dei tipi gestisce l’unpacking di una tupla con asterisco e la chiamata al costruttore, quindi aggiorna il comportamento in modo che il riproduttore non segnali errori di tipo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 45/100