The Wayback Machine - https://web.archive.org/web/20240503020752/https://github.com/python/cpython/issues/117894
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
graingert opened this issue Apr 15, 2024 · 0 comments
Open

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

graingert opened this issue Apr 15, 2024 · 0 comments
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Apr 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant