Since 1.6.0 TypeVar with bound types fails to match with Callable of the same bound 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
Did not occur prior to 1.6.0.
https://github.com/python-cmd2/cmd2/actions/runs/6699406223/job/18203570049
Got the following error with mypy:
cmd2/cmd2.py: note: In member "_build_parser" of class "Cmd":
cmd2/cmd2.py:699:46: error: Argument 1 has incompatible type "CommandParent"; expected "Union[Type[Cmd], Type[CommandSet]]" [arg-type]
Found 1 error in 1 file (checked 18 source files)
where CommandParent is a TypeVar declared as:
CommandParent = TypeVar('CommandParent', bound=Union['cmd2.Cmd', CommandSet])
To Reproduce
https://github.com/python-cmd2/cmd2/blob/8d88c357ca0764b114c68d8175d2cd33146b83d7/cmd2/cmd2.py#L694
Expected Behavior
Since CommandParent is bound to the expected type, this shouldn't be an error
Actual Behavior
I get the error above.
Your Environment
- Mypy version used: 1.6.1
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.8, 3.9,3.10,3.11
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
Riproduci il malfunzionamento di cmd2/cmd2.py intorno alla riga 694 usando mypy 1.6.1 e le versioni di Python indicate. Confronta il bound di TypeVar con la gestione degli argomenti di Callable, quindi verifica che i tipi compatibili indicati non producano più l’errore arg-type.
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
- Abbastanza chiara
- Idoneità per principianti
- 35/100