python / python/mypy

`has no attribute "__aiter__"; maybe "__enter__"? (not async iterable)` when async iterating

Aperta
#17,126 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

On mypy 1.9.0, this code suggests, somewhat nonsensically, __enter__ because __aiter__ does not exist despite the reference to __aiter__ being entirely implicit in the async for loop:

from typing import Self

class Foo:
    def __enter__(self) -> Self:
        return self

async def f() -> None:
    async for x in Foo():
        print(x)

On playground: https://mypy-play.net/?mypy=latest&python=3.12&gist=3971471bd809ed97a72a1423a56f5318

Expected Behavior

Since the user did not type __aiter__, it is unlikely that it would be a typo for __enter__; therefore, probably the most helpful course would be to not give that suggestion.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo la diagnostica con l'esempio Python nell'issue e confrontala con il risultato collegato di mypy playground. Traccia la gestione dell'errore async-for e dei suggerimenti, quindi verifica che un riferimento implicito a aiter non suggerisca più enter; la diagnostica corretta dovrebbe comunque spiegare che Foo non è iterabile in modo asincrono.

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
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.