mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
bpo-43146: fix None-handling in single-arg traceback.print_exception(None) (GH-24629)
(The previous commit fixed print_exception(None, None, None).)
This commit is contained in:
parent
26f18b8540
commit
b798ab0693
3 changed files with 10 additions and 1 deletions
|
@ -234,6 +234,10 @@ class TracebackCases(unittest.TestCase):
|
||||||
|
|
||||||
def test_exception_is_None(self):
|
def test_exception_is_None(self):
|
||||||
NONE_EXC_STRING = 'NoneType: None\n'
|
NONE_EXC_STRING = 'NoneType: None\n'
|
||||||
|
excfile = StringIO()
|
||||||
|
traceback.print_exception(None, file=excfile)
|
||||||
|
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
|
||||||
|
|
||||||
excfile = StringIO()
|
excfile = StringIO()
|
||||||
traceback.print_exception(None, None, None, file=excfile)
|
traceback.print_exception(None, None, None, file=excfile)
|
||||||
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
|
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
|
||||||
|
@ -243,6 +247,7 @@ class TracebackCases(unittest.TestCase):
|
||||||
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
|
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
|
||||||
|
|
||||||
self.assertEqual(traceback.format_exc(None), NONE_EXC_STRING)
|
self.assertEqual(traceback.format_exc(None), NONE_EXC_STRING)
|
||||||
|
self.assertEqual(traceback.format_exception(None), [NONE_EXC_STRING])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
traceback.format_exception(None, None, None), [NONE_EXC_STRING])
|
traceback.format_exception(None, None, None), [NONE_EXC_STRING])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
|
@ -91,7 +91,10 @@ def _parse_value_tb(exc, value, tb):
|
||||||
if (value is _sentinel) != (tb is _sentinel):
|
if (value is _sentinel) != (tb is _sentinel):
|
||||||
raise ValueError("Both or neither of value and tb must be given")
|
raise ValueError("Both or neither of value and tb must be given")
|
||||||
if value is tb is _sentinel:
|
if value is tb is _sentinel:
|
||||||
|
if exc is not None:
|
||||||
return exc, exc.__traceback__
|
return exc, exc.__traceback__
|
||||||
|
else:
|
||||||
|
return None, None
|
||||||
return value, tb
|
return value, tb
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Handle None in single-arg versions of :func:`~traceback.print_exception` and :func:`~traceback.format_exception`.
|
Loading…
Add table
Add a link
Reference in a new issue