Skip to content

Commit a589114

Browse files
committed
Print exception type name instead of its representation
1 parent 2fe44f7 commit a589114

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Lib/test/test_ctypes/test_structures.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ class Person(Structure):
332332
cls, msg = self.get_except(Person, b"Someone", (1, 2))
333333
self.assertEqual(cls, RuntimeError)
334334
self.assertEqual(msg,
335-
"(Phone) <class 'TypeError'>: "
335+
"(Phone) TypeError: "
336336
"expected bytes, int found")
337337

338338
cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c"))
339339
self.assertEqual(cls, RuntimeError)
340340
self.assertEqual(msg,
341-
"(Phone) <class 'TypeError'>: too many initializers")
341+
"(Phone) TypeError: too many initializers")
342342

343343
def test_huge_field_name(self):
344344
# issue12881: segfault with large structure field names

Modules/_ctypes/callproc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...)
10191019

10201020
PyErr_Fetch(&tp, &v, &tb);
10211021
PyErr_NormalizeException(&tp, &v, &tb);
1022-
cls_str = PyObject_Str(tp);
1022+
cls_str = PyUnicode_FromString(((PyTypeObject *)tp)->tp_name);
10231023
if (cls_str) {
10241024
PyUnicode_AppendAndDel(&s, cls_str);
10251025
PyUnicode_AppendAndDel(&s, PyUnicode_FromString(": "));

0 commit comments

Comments
 (0)