Remove binding of captured exceptions when not used to reduce the chances of creating cycles (GH-17246)
Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles.
See for example GH-13135
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index e1638c1..3aec34c 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -11,7 +11,7 @@
try:
import _testcapi
-except ImportError as exc:
+except ImportError:
_testcapi = None
try: