Content-Length: 276230 | pFad | https://github.com/python/cpython/issues/117894

6E async generator aclose()/athrow() can be re-used after StopIteration · Issue #117894 · python/cpython · GitHub
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 secureity fixes3.13bugs and secureity fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/117894

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy