iter(...) is not revealed the same as __iter__ method
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
We are having issues with the pandas-stubs repo where the inference for __iter__ is different with iter(...).
With __iter__ we are seeing the right inference while with iter(...)
To Reproduce
from typing import Any, Generic, Never, TypeVar, reveal_type
_T_EXPANDING = TypeVar("_T_EXPANDING")
_T_STR = TypeVar("_T_STR", bound=Series)
class StringMethods(Generic[_T_EXPANDING, _T_STR]):
def __getitem__(self, key: int) -> _T_STR: ...
def __iter__(self) -> Never: ...
class Series:
@property
def str(self) -> StringMethods[Any, Series]: ...
def _0() -> None:
reveal_type(StringMethods().__iter__()) # all 4 type checkers give Never
def _1() -> None:
reveal_type(iter(Series().str)) # mypy: Any, pyright, pyrefly: Never, ty: Unknown
Expected Behavior
It is identifying it as Any.
Actual Behavior
We expect Never.
Your Environment
- Mypy version used: mypy 1.19.1 (compiled: yes)
- Mypy command-line flags: mypy test_file.py
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.14
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 Python fornito con mypy 1.19.1 e confronta reveal_type(StringMethods().iter()) con reveal_type(iter(Series().str)). Traccia la gestione dell’espressione iter(...) rispetto al metodo iter; il lavoro è completato quando mypy segnala Never per il caso iter(...), senza modificare il comportamento previsto altrove.
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
- Specificata chiaramente
- Idoneità per principianti
- 48/100