mypy infers `numpy.float64` instead of `Any` for `numpy.ndarray.__iter__` in numpy 2.2.2
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
It looks like mypy doesn't correctly handle the overloading of numpy.ndarray.__iter__. In the example below mypy infers numpy.float64 for ai while the correct type is Any.
See also: https://github.com/numpy/numpy/issues/28245
To Reproduce
import numpy as np
import numpy.typing as npt
a: npt.NDArray[np.float64] = np.ones([2, 2])
for _, ai in enumerate(a):
reveal_type(ai)
Expected Behavior
Any
Actual Behavior
test.py:7: note: Revealed type is "numpy.float64"
Your Environment
Both pyright 1.1.392 and basedpyright 1.25.0 behave as expected.
- Mypy version used: mypy 1.14.1 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.12.8 (main, Jan 22 2025, 21:56:05) [GCC 11.4.0]
- Numpy version used: 2.2.2
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der test.py-Reproduktion und führe sie unter mypy 1.14.1 mit den im Bericht aufgeführten Versionen aus. Verfolge, wie mypy das Ergebnis von numpy.ndarray.iter mit Überladungen verarbeitet, und bestätige anschließend die Korrektur, indem du überprüfst, dass reveal_type(ai) für das bereitgestellte Beispiel Any meldet.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- numpy, python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100