GeezerVison is showing github.com — gh-92119: ctypes: Print exception class name instead of its represent… · python/cpython@2d00190
File treeExpand file treeCollapse file tree Open diff view settings Misc/NEWS.d/next/Core and Builtins
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Doc/library/ctypes.rst +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -358,7 +358,7 @@ from within *IDLE* or *PythonWin*:: | 358 | 358 | >>> printf(b"%f bottles of beer\n", 42.5) | 359 | 359 | Traceback (most recent call last): | 360 | 360 | File "<stdin>", line 1, in <module> | 361 | | - ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2 | | 361 | + ArgumentError: argument 2: TypeError: Don't know how to convert parameter 2 | 362 | 362 | >>> | 363 | 363 |
| 364 | 364 | As has been mentioned before, all Python types except integers, strings, and | @@ -421,7 +421,7 @@ prototype for a C function), and tries to convert the arguments to valid types:: | 421 | 421 | >>> printf(b"%d %d %d", 1, 2, 3) | 422 | 422 | Traceback (most recent call last): | 423 | 423 | File "<stdin>", line 1, in <module> | 424 | | - ArgumentError: argument 2: exceptions.TypeError: wrong type | | 424 | + ArgumentError: argument 2: TypeError: wrong type | 425 | 425 | >>> printf(b"%s %d %f\n", b"X", 2, 3) | 426 | 426 | X 2 3.000000 | 427 | 427 | 13 | @@ -471,7 +471,7 @@ single character Python bytes object into a C char:: | 471 | 471 | >>> strchr(b"abcdef", b"def") | 472 | 472 | Traceback (most recent call last): | 473 | 473 | File "<stdin>", line 1, in <module> | 474 | | - ArgumentError: argument 2: exceptions.TypeError: one character string expected | | 474 | + ArgumentError: argument 2: TypeError: one character string expected | 475 | 475 | >>> print(strchr(b"abcdef", b"x")) | 476 | 476 | None | 477 | 477 | >>> strchr(b"abcdef", b"d") | |
Collapse file Copy file name to clipboardExpand all lines: Lib/ctypes/test/test_structures.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -332,13 +332,13 @@ class Person(Structure): | 332 | 332 | cls, msg = self.get_except(Person, b"Someone", (1, 2)) | 333 | 333 | self.assertEqual(cls, RuntimeError) | 334 | 334 | self.assertEqual(msg, | 335 | | - "(Phone) <class 'TypeError'>: " | | 335 | + "(Phone) TypeError: " | 336 | 336 | "expected bytes, int found") | 337 | 337 |
| 338 | 338 | cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c")) | 339 | 339 | self.assertEqual(cls, RuntimeError) | 340 | 340 | self.assertEqual(msg, | 341 | | - "(Phone) <class 'TypeError'>: too many initializers") | | 341 | + "(Phone) TypeError: too many initializers") | 342 | 342 |
| 343 | 343 | def test_huge_field_name(self): | 344 | 344 | # issue12881: segfault with large structure field names | |
Collapse file Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Print exception class name instead of its string representation when raising | | 2 | +errors from :mod:`ctypes` calls. |
Collapse file Copy file name to clipboardExpand all lines: Modules/_ctypes/callproc.c +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1016,7 +1016,10 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...) | 1016 | 1016 |
| 1017 | 1017 | PyErr_Fetch(&tp, &v, &tb); | 1018 | 1018 | PyErr_NormalizeException(&tp, &v, &tb); | 1019 | | - cls_str = PyObject_Str(tp); | | 1019 | + if (PyType_Check(tp)) | | 1020 | + cls_str = PyType_GetName((PyTypeObject *)tp); | | 1021 | + else | | 1022 | + cls_str = PyObject_Str(tp); | 1020 | 1023 | if (cls_str) { | 1021 | 1024 | PyUnicode_AppendAndDel(&s, cls_str); | 1022 | 1025 | PyUnicode_AppendAndDel(&s, PyUnicode_FromString(": ")); | |
|