From e31e36b40c975ffc41dfee4e4921e260cd5c12b9 Mon Sep 17 00:00:00 2001 From: user202729 <25191436+user202729@users.noreply.github.com> Date: Sat, 25 Jan 2025 10:07:24 +0700 Subject: [PATCH] Avoid cyclic reference in contextmanager --- Lib/contextlib.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 5b646fabca0225..f5bdf9b0e409a2 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -164,7 +164,9 @@ def __exit__(self, typ, value, traceback): # Suppress StopIteration *unless* it's the same exception that # was passed to throw(). This prevents a StopIteration # raised inside the "with" statement from being suppressed. - return exc is not value + result = exc is not value + del exc, value # avoid cyclic reference + return result except RuntimeError as exc: # Don't re-raise the passed in exception. (issue27122) if exc is value: