Allow Return Statements with Values in Asynchronous Generators
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Feature or enhancement
Proposal:
async def gen():
yield 1
yield 2
return 3
async def runner():
g = gen()
while True:
try:
a = await g.__anext__()
print("yielded", a)
except StopAsyncIteration as e:
print("returned", e.value)
break
asyncio.run(runner())
# yielded 1
# yielded 2
# returned 3
The proposal adds optional return values to async generators.
This feature should be implemented to achieve syntactic and functional parity with synchronous generators.
Today:
def gen():
yield 1
yield 2
return 3
async def agen():
yield 1
yield 2
return 3 # Syntax error
Proposal:
def gen():
yield 1
yield 2
return 3
async def agen():
yield 1
yield 2
return 3
It can be implemented trivially in CPython as a nonbreaking change.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/allow-return-statements-with-values-in-asynchronous-generators/66886
Linked PRs
- gh-125401
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 leggendo la discussione di Discourse collegata e la PR collegata gh-125401 per comprendere le modifiche proposte al linguaggio e al runtime. Usa l’esempio di generatore asincrono nell’issue come riferimento comportamentale; il lavoro è completo quando un generatore asincrono può restituire un valore e tale valore è osservabile tramite StopAsyncIteration senza interrompere il comportamento esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 20/100