GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-92119: ctypes: Print exception class name instead of its represent… · python/cpython@2d00190

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Doc/library
    • ctypes.rst
  • Lib/ctypes/test
    • test_structures.py
  • Misc/NEWS.d/next/Core and Builtins
    • 2022-10-15-23-15-14.gh-issue-92119.PMSwwG.rst
  • Modules/_ctypes
    • callproc.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Doc/library/ctypes.rst‎

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 numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ from within *IDLE* or *PythonWin*::
358358
>>> printf(b"%f bottles of beer\n", 42.5)
359359
Traceback (most recent call last):
360360
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
362362
>>>
363363

364364
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::
421421
>>> printf(b"%d %d %d", 1, 2, 3)
422422
Traceback (most recent call last):
423423
File "<stdin>", line 1, in <module>
424-
ArgumentError: argument 2: exceptions.TypeError: wrong type
424+
ArgumentError: argument 2: TypeError: wrong type
425425
>>> printf(b"%s %d %f\n", b"X", 2, 3)
426426
X 2 3.000000
427427
13
@@ -471,7 +471,7 @@ single character Python bytes object into a C char::
471471
>>> strchr(b"abcdef", b"def")
472472
Traceback (most recent call last):
473473
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
475475
>>> print(strchr(b"abcdef", b"x"))
476476
None
477477
>>> strchr(b"abcdef", b"d")
Collapse file

‎Lib/ctypes/test/test_structures.py‎

Copy file name to clipboardExpand all lines: Lib/ctypes/test/test_structures.py
+2-2Lines changed: 2 additions & 2 deletions
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
Collapse file

‎Misc/NEWS.d/next/Core and Builtins/2022-10-15-23-15-14.gh-issue-92119.PMSwwG.rst‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Print exception class name instead of its string representation when raising
2+
errors from :mod:`ctypes` calls.
Collapse file

‎Modules/_ctypes/callproc.c‎

Copy file name to clipboardExpand all lines: Modules/_ctypes/callproc.c
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,10 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...)
10161016

10171017
PyErr_Fetch(&tp, &v, &tb);
10181018
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);
10201023
if (cls_str) {
10211024
PyUnicode_AppendAndDel(&s, cls_str);
10221025
PyUnicode_AppendAndDel(&s, PyUnicode_FromString(": "));

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.