Skip to content

async generator aclose()/athrow() can be re-used after StopIteration #117894

@graingert

Description

@graingert

Bug report

Bug description:

class MyExc(Exception): pass import itertools async def agenfn(): for i in itertools.count(): try: yield i except MyExc: pass agen = agenfn() try: agen.asend(None).send(None) except StopIteration as e: print(f"{e.value=}") athrow = agen.athrow(MyExc) try: athrow.throw(MyExc) except StopIteration as e: print(f"{e.value=}") try: athrow.throw(MyExc) except RuntimeError: print("good") except StopIteration as e: print(f"bad {e.value=}")

outputs:

e.value=0 e.value=1 bad e.value=2 

should output:

e.value=0 e.value=1 good 

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions