[3.10] bpo-45083: Include the exception class qualname when formatting an exception (GH-28119) (GH-28134)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
(cherry picked from commit b4b6342848ec0459182a992151099252434cc619)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* Use a private version of _PyType_GetQualName
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 1fd5247..8717def 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1069,6 +1069,20 @@ def __del__(self):
self.assertIn("del is broken", report)
self.assertTrue(report.endswith("\n"))
+ def test_original_unraisablehook_exception_qualname(self):
+ class A:
+ class B:
+ class X(Exception):
+ pass
+
+ with test.support.captured_stderr() as stderr, \
+ test.support.swap_attr(sys, 'unraisablehook',
+ sys.__unraisablehook__):
+ expected = self.write_unraisable_exc(
+ A.B.X(), "msg", "obj");
+ report = stderr.getvalue()
+ testName = 'test_original_unraisablehook_exception_qualname'
+ self.assertIn(f"{testName}.<locals>.A.B.X", report)
def test_original_unraisablehook_wrong_type(self):
exc = ValueError(42)