Errors on multi-variable assignments of types
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
MyPy seems to have issues when multi-variable assignments of types to their aliases are involved.
To Reproduce
Run mypy on the following two sources:
from typing import Any
typ_a = Any
typ_b = Any
def test1(x: typ_a, y: typ_b): pass
from typing import Any
typ_a, typ_b = Any, Any
def test2(x: typ_a, y: typ_b): pass
typ_a = typ_b = Any
def test3(x: typ_a, y: typ_b): pass
Expected Behavior
MyPy does not show any errors for any of the function's signatures, since they are all essentially the same.
Actual Behavior
MyPy shows the following errors for test2 and test3:
repro2.py:4: error: Variable "repro2.typ_a" is not valid as a type
repro2.py:4: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
repro2.py:4: error: Variable "repro2.typ_b" is not valid as a type
repro2.py:7: error: Variable "repro2.typ_a" is not valid as a type
repro2.py:7: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
repro2.py:7: error: Variable "repro2.typ_b" is not valid as a type
Found 4 errors in 1 file (checked 1 source file)
Confusingly, if one merges the two source files, no errors are shown.
Your Environment
- Mypy version used: 0.800
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.9.1
- Operating system and version: Ubuntu 20.04
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 eseguendo mypy sulle tre riproduzioni in repro2.py e confronta il modo in cui le assegnazioni singole, di tuple e concatenate vengono registrate come alias di tipo. Traccia il percorso del type-checking per queste assegnazioni e le annotazioni delle funzioni; il lavoro è completato quando tutte e tre le signature non producono errori, mentre i controlli esistenti su alias e variabili rimangono invariati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100