-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Consider the following code.
from contextlib import contextmanager
class MyException(Exception):
def __del__(self):
print("deleted")
@contextmanager
def f():
try:
yield
except MyException:
pass
with f():
raise MyException()
print("done")In Python 3.11 the printed value is deleted done, in Python 3.12 the printed value is done deleted. Which means the exception is kept around much longer than it need to be, this is caused by a reference cycle between the exception and the frame in contextmanager implementation.
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error