diff options
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/test_traceback.py | 11 | ||||
| -rw-r--r-- | Lib/traceback.py | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index d88851d..cde35f5 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1254,6 +1254,17 @@ class BaseExceptionReportingTests: exp = "%s: %s\n" % (str_name, str_value) self.assertEqual(exp, err) + def test_exception_modulename_not_unicode(self): + class X(Exception): + def __str__(self): + return "I am X" + + X.__module__ = 42 + + err = self.get_report(X()) + exp = f'<unknown>.{X.__qualname__}: I am X\n' + self.assertEqual(exp, err) + def test_exception_bad__str__(self): class X(Exception): def __str__(self): diff --git a/Lib/traceback.py b/Lib/traceback.py index 97caa13..77f8590 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -808,6 +808,8 @@ class TracebackException: stype = self.exc_type.__qualname__ smod = self.exc_type.__module__ if smod not in ("__main__", "builtins"): + if not isinstance(smod, str): + smod = "<unknown>" stype = smod + '.' + stype if not issubclass(self.exc_type, SyntaxError): |
