redundant-expr does not work with TypeVar with multiple constraints
Aperta
Nessuno ha ancora preso questa issue.
bug
topic-type-variables
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
A TypeVar with multiple constraints can be seen as a union. However, the redundant-expr does not understand it and emits errors which are wrong.
To Reproduce
from typing import TypeVar
T = TypeVar("T", int, str)
def foo(var: T) -> T:
return "aa" if isinstance(var, str) else 0
Expected Behavior
no error
Actual Behavior
foo.py:9:20: error: If condition is always false [redundant-expr]
return "aa" if isinstance(var, str) else 0
^~~~~~~~~~~~~~~~~~~~
foo.py:9:20: error: If condition is always true [redundant-expr]
return "aa" if isinstance(var, str) else 0
^~~~~~~~~~~~~~~~~~~~
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.14.1
- Mypy command-line flags:
--enable-error-code redundant-expr - Python version used: 3.13.0
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 l'esempio TypeVar fornito con mypy 1.14.1 e --enable-error-code redundant-expr. Traccia l'analisi redundant-expr per i TypeVars vincolati, quindi aggiungi un test di regressione che mostri che il controllo isinstance non produce errori ed esegui la suite di test pertinente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100