Skip to content

bpo-46510: Add missing test for types.TracebackType/FrameType. Calculate them directly from the caught exception. #30880

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

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,14 @@ def test_notimplemented_type(self):
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):

Expand Down
8 changes: 3 additions & 5 deletions Lib/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ def _m(self): pass

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__)
Expand Down
Original file line number Diff line number Diff line change
@@ -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`.