`for` loop over a subclass ignores its overridden `__iter__` and uses the base class's type argument
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- backend-api-design, tooling
Direzione di ricerca
The reproducer shows that iter(b) infers Iterator[int], while for loops and comprehensions infer object; start by running the Python example in the Pyrefly sandbox and tracing how iteration types are inferred for each construct. Find the relevant Rust implementation and regression tests for for loops and comprehensions. Done means both infer int for this subclass and existing iteration tests still pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the Bug
from collections.abc import Iterable, Iterator
from typing import reveal_type
class B(Iterable[object]):
def __iter__(self) -> Iterator[int]:
yield 1
def f(b: B) -> None:
reveal_type(iter(b)) # Iterator[int]
for y in b:
reveal_type(y) # expected int, got object
y + 1 # false positive
reveal_type([y for y in b]) # expected list[int], got list[object]
Spotted in Requests
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
- Lingua principale
- Rust
- Stelle
- 7.2k
- Fork
- 578
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi 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.
Altre issue di facebook/pyrefly
-
Should `--preset=basic` show `reveal_type`?Forse già presa @MarcoGorelli l’ha presa oggi. Apertaquansight
-
Hover does not show pathlib.Path.read_text docstringForse già presa @1-DARK l’ha presa oggi. Apertalanguage-server
-
`unbound-name` not reported after a for loop that contains `break`Forse già presa @1-DARK l’ha presa oggi. Apertascoping-control-flow
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
scoping-control-flow
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
-
py3.15: error with sentinel + type qualifier (Final / ClassVar)Forse già presa @1-DARK l’ha presa oggi. Apertapy3.15
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Tutte le issue di facebook/pyrefly
Issue simili
-
ai_p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ClickHouse/ClickHouse#130006 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
horizon-rust/horizon#12071 ·
I maintainer di solito rispondono entro 1 giorno
-
bug priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
storytold/photocraft#12183 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
area:render needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
bherbruck/solvecraft#13138 ·
-
testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100