Generic argument is not being identified
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
The code in this mypy playground raises the following error.
Name "T" is not defined [name-defined]
However, as seen in this pyright playground there is no error, which leads me to believe that the snippet is well defined.
This one is probably related but the revealed types do not seem to match as well (the ? in the type name seems to be rather strange).
mypy
"__main__.Repo[T?, U`-2]"
pyright
"Repo[T@some, U@some]"
To Reproduce (this is the same code as in the mypy playground)
from typing import cast, reveal_type
from collections.abc import Callable
class Repo[T, U]: ...
def some[T, U, **P](func: Callable[P, U]) -> Callable[P, U]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> U:
reveal_type(cast(Repo[T, U], args[0]))
return func(*args, **kwargs)
return wrapper
Expected Behavior
No errors from mypy, similar behavior to pyright.
Actual Behavior
I am not sure if mypy is misdiagnosing this, if you feel this is intended behavior I can try raising an issue with pyright.
Your Environment
- Mypy version used: 1.15.0 (playground)
- Pyright version used: 1.1.399 (playground)
- Mypy command-line flags: default settings in mypy playground (if I am not mistaken, there are no extra flags)
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.13 (for both playgrounds)
Thank You
Edit: Simplified the example a bit by removing the bounds and awaitables.
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 il playground mypy collegato e la riproduzione minima sotto “To Reproduce”, confrontando il risultato con quello del playground pyright collegato. Traccia come vengono risolti i parametri generici T e U all'interno di wrapper e in cast(Repo[T, U], args[0]); il lavoro è completato quando mypy non segnala più T come non definito e il suo tipo rivelato è coerente con la forma generica prevista.
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
- 38/100