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

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

Closed
graingert opened this issue Aug 11, 2022 · 3 comments
Closed
Labels
3.11 only security fixes 3.12 bugs and security fixes

Comments

@graingert
Copy link
Contributor

graingert commented Aug 11, 2022

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

@graingert graingert added 3.11 only security fixes 3.12 bugs and security fixes labels Aug 11, 2022
@graingert
Copy link
Contributor Author

see also #27024

@graingert
Copy link
Contributor Author

graingert commented Aug 11, 2022

I think the test cases and code for contextlib.contextmanager and contextlib.ExitStack should be automatically generated from the test cases and code for contextlib.asynccontextmanager and contextlib.AsyncExitStack

this is done in httpcore with https://github.com/encode/httpcore/blob/master/unasync.py

@iritkatriel
Copy link
Member

Unassigned myself since you are working on it.

iritkatriel added a commit to iritkatriel/cpython that referenced this issue Jan 3, 2023
iritkatriel pushed a commit that referenced this issue Jan 3, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 3, 2023
…ted from inside a contextlib context manager (pythonGH-95883)

(cherry picked from commit b3722ca)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
miss-islington added a commit that referenced this issue Jan 3, 2023
…om inside a contextlib context manager (GH-95883)

(cherry picked from commit b3722ca)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes
Projects
None yet
Development

No branches or pull requests

2 participants