Skip to content

Commit fcaa76e

Browse files
authored
Merge pull request #36 from Delgan/GH-35-fix-none-exception
Fix ValueError while formatting None-tuple exception
2 parents e08a8f5 + a5672c5 commit fcaa76e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

stackprinter/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ def _is_exc_info(thing):
310310
if not isinstance(thing, tuple) or len(thing) != 3:
311311
return False
312312
a, b, c = thing
313-
return (isinstance(a, type) and BaseException in a.mro() and
314-
isinstance(b, BaseException))
313+
return ((a is None or (isinstance(a, type) and BaseException in a.mro())) and
314+
(b is None or (isinstance(b, BaseException))))
315315

316316
def format_thread(thread, add_summary=False, **kwargs):
317317
try:

stackprinter/formatting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def format_exc_info(etype, evalue, tb, style='plaintext', add_summary='auto',
117117
118118
see stackprinter.format() for docs about the keyword arguments
119119
"""
120+
if etype is None:
121+
etype = type(None)
122+
120123
msg = ''
121124
try:
122125
# First, recursively format any chained exceptions (exceptions

tests/test_formatting.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ def test_exception_formatting():
4747
print(msg_color)
4848

4949

50+
def test_none_tuple_formatting():
51+
output = stackprinter.format((None, None, None))
52+
assert output == "NoneType: None"
5053

54+
55+
def test_none_value_formatting():
56+
output = stackprinter.format((TypeError, None, None))
57+
assert output == "TypeError: None"

0 commit comments

Comments
 (0)