Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
bpo-43146: fix None-handling in single-arg version of traceback.print…
…_exception() and traceback.format_exception()
  • Loading branch information
iritkatriel committed Feb 23, 2021
commit fe4b1b4dc1a3e267733cf1523ba41852c1577f49
5 changes: 5 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def test_format_exception_only_exc(self):

def test_exception_is_None(self):
NONE_EXC_STRING = 'NoneType: None\n'
excfile = StringIO()
traceback.print_exception(None, file=excfile)
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)

excfile = StringIO()
traceback.print_exception(None, None, None, file=excfile)
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
Expand All @@ -243,6 +247,7 @@ def test_exception_is_None(self):
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)

self.assertEqual(traceback.format_exc(None), NONE_EXC_STRING)
self.assertEqual(traceback.format_exception(None), [NONE_EXC_STRING])
self.assertEqual(
traceback.format_exception(None, None, None), [NONE_EXC_STRING])
self.assertEqual(
Expand Down
5 changes: 4 additions & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def _parse_value_tb(exc, value, tb):
if (value is _sentinel) != (tb is _sentinel):
raise ValueError("Both or neither of value and tb must be given")
if value is tb is _sentinel:
return exc, exc.__traceback__
if exc is not None:
return exc, exc.__traceback__
else:
return None, None
return value, tb


Expand Down