Skip to content

Trackstack includes __aexit__ in contextlib which is not in previous versions #95882

@graingert

Description

@graingert
import contextlib


@contextlib.asynccontextmanager
async def f():
    try:
        yield
    finally:
        pass

async def amain():
    async with f(): 1/0


with contextlib.closing(amain().__await__()) as gen:
    next(gen, None)
Traceback (most recent call last):
  File "/home/graingert/projects/cpython/demo.py", line 16, in <module>
    next(gen, None)
  File "/usr/lib/python3.11/contextlib.py", line 222, in __aexit__
    await self.gen.athrow(typ, value, traceback)
  File "/home/graingert/projects/cpython/demo.py", line 7, in f
    yield
  File "/home/graingert/projects/cpython/demo.py", line 12, in amain
    async with f(): 1/0
                    ~^~
ZeroDivisionError: division by zero

Originally posted by @graingert in #92118 (comment)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions