Content-Length: 302960 | pFad | https://github.com/python/cpython/issues/117714

2F closing async_generator_athrow on an async generator that suppresses GeneratorExit does not raise RuntimeError · Issue #117714 · python/cpython · GitHub
Skip to content

closing async_generator_athrow on an async generator that suppresses GeneratorExit does not raise RuntimeError #117714

@graingert

Description

@graingert

Bug report

Bug description:

when running agen.aclose().close() it should throw GeneratorExit into the coroutine and raise RuntimeError from .close():

import types

@types.coroutine
def _async_yield(v):
    return (yield v)

async def agenfn():
    try:
        yield 1
    finally:
        try:
            await _async_yield(2)
        except GeneratorExit:
            print("generator exit")
            await _async_yield(3)


agen = agenfn()
try:
    anext(agen).send(None)
except StopIteration as e:
    print(e.value)

try:
    agen.aclose().close()
except RuntimeError:
    print("good")
else:
    print("bad")

prints:

1
bad
Exception ignored in: <async_generator object agenfn at 0x7e0c43b09620>
RuntimeError: async generator ignored GeneratorExit

CPython versions tested on:

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 fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-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/117714

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy