mypy doesn't escape typevars from generics in self-type
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
Passing a callable to another which matches the typevar with another typevar doesn't allow passing them into the return type. (if that makes no sense, the reproducer below is simple)
To Reproduce
from typing import Generic, TypeVar, Callable
T = TypeVar("T")
V = TypeVar("V")
class X(Generic[T]):
def f(self: X[Callable[[V], None]]) -> Callable[[V], V]:
def inner_f(v: V) -> V:
return v
return inner_f
reveal_type(X[Callable[[T], None]]().f()) # N: Revealed type is "def (Never) -> Never"
# ^ this should keep the generic
Expected Behavior
I don't expect a Never.
Your Environment
Checked on mypy playground.
- Mypy version used: v1.14
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.12
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 il riproduttore generico del self-type fornito con mypy v1.14 e --strict, quindi esamina come reveal_type risolve XCallable[[T], None].f(). Traccia il percorso di inferenza dei tipi responsabile del risultato e considera completata la issue quando la Callable restituita conserva il suo tipo generico invece di diventare (Never) -> Never.
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
- 42/100