Generic argument is not being identified
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el playground de mypy enlazado y la reproducción mínima bajo “To Reproduce”, comparando su resultado con el playground de pyright enlazado. Traza cómo se resuelven los parámetros genéricos T y U dentro de wrapper y en cast(Repo[T, U], args[0]); el trabajo está terminado cuando mypy ya no informa de que T está indefinido y su tipo revelado es coherente con la forma genérica esperada.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100