]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46510: Add missing test for types.TracebackType/FrameType. Calculate them directl...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Tue, 25 Jan 2022 18:00:57 +0000 (18:00 +0000)
committerGitHub <noreply@github.com>
Tue, 25 Jan 2022 18:00:57 +0000 (18:00 +0000)
Lib/test/test_types.py
Lib/types.py
Misc/NEWS.d/next/Library/2022-01-25-10-59-41.bpo-46510.PM5svI.rst [new file with mode: 0644]

index 3dfda5cb9566369a666a82445ed88e002b491a59..c54854eeb5ad221688aa5f7ed4fc50157d5b5f8e 100644 (file)
@@ -624,6 +624,14 @@ class TypesTests(unittest.TestCase):
     def test_none_type(self):
         self.assertIsInstance(None, types.NoneType)
 
+    def test_traceback_and_frame_types(self):
+        try:
+            raise OSError
+        except OSError as e:
+            exc = e
+        self.assertIsInstance(exc.__traceback__, types.TracebackType)
+        self.assertIsInstance(exc.__traceback__.tb_frame, types.FrameType)
+
 
 class UnionTests(unittest.TestCase):
 
index 679c7f638b3100abcb069c8bb05a5331a67c1631..9490da7b9ee3b9911a24285c628823fc68b182d6 100644 (file)
@@ -52,11 +52,9 @@ ModuleType = type(sys)
 
 try:
     raise TypeError
-except TypeError:
-    tb = sys.exc_info()[2]
-    TracebackType = type(tb)
-    FrameType = type(tb.tb_frame)
-    tb = None; del tb
+except TypeError as exc:
+    TracebackType = type(exc.__traceback__)
+    FrameType = type(exc.__traceback__.tb_frame)
 
 # For Jython, the following two types are identical
 GetSetDescriptorType = type(FunctionType.__code__)
diff --git a/Misc/NEWS.d/next/Library/2022-01-25-10-59-41.bpo-46510.PM5svI.rst b/Misc/NEWS.d/next/Library/2022-01-25-10-59-41.bpo-46510.PM5svI.rst
new file mode 100644 (file)
index 0000000..b416a16
--- /dev/null
@@ -0,0 +1,3 @@
+Add missing test for :class:`types.TracebackType` and
+:class:`types.FrameType`. Calculate them directly from the caught exception
+without calling :func:`sys.exc_info`.