Incorrect resolution of `type[TypeVar]` returning `TypeVar` with `numpy`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
Descrizione
Bug Report
This came up with pandas-stubs, but can reproduce with just numpy
To Reproduce
from typing import TypeVar
import numpy as np
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray)
def foo(x: type[NDArrayT]) -> NDArrayT:
return x([1, 2])
reveal_type(foo(np.ndarray))
Expected Behavior
Revealed type should be ndarray[tuple[Any, ...], dtype[Any]], which is what pyright reports.
Actual Behavior
mypy reports numpy.ndarray[Any, Any]
Your Environment
- Mypy version used: 1.19.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11
- numpy version: 2.3.5
- pyright version: 1.1.407
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 la riproduzione Python fornita con mypy 1.19.0 e confronta il tipo rivelato da essa con il risultato di pyright. Traccia l’inferenza del tipo per type[TypeVar] e ndarray, quindi aggiungi un test di regressione che mostri che foo(np.ndarray) rivela il tipo ndarray previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- numpy, 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
- 42/100