gh-92119: Print exception class name instead of its representation#98302
gh-92119: Print exception class name instead of its representation#98302JelleZijlstra merged 6 commits intopython:mainfrom
Conversation
Doc/library/ctypes.rst
Outdated
| Traceback (most recent call last): | ||
| File "<stdin>", line 1, in <module> | ||
| ArgumentError: argument 2: exceptions.TypeError: one character string expected | ||
| ArgumentError: argument 2: TypeError: wrong type |
There was a problem hiding this comment.
That's the actual error message.
There was a problem hiding this comment.
Probably best kept for a separate PR, but I wonder why we don't run these tests as part of the doctest suite.
There was a problem hiding this comment.
OK, I will create a separate PR for this. Reverted the change for now.
Doc/library/ctypes.rst
Outdated
| Traceback (most recent call last): | ||
| File "<stdin>", line 1, in <module> | ||
| ArgumentError: argument 2: exceptions.TypeError: one character string expected | ||
| ArgumentError: argument 2: TypeError: wrong type |
There was a problem hiding this comment.
Probably best kept for a separate PR, but I wonder why we don't run these tests as part of the doctest suite.
Modules/_ctypes/callproc.c
Outdated
| PyErr_Fetch(&tp, &v, &tb); | ||
| PyErr_NormalizeException(&tp, &v, &tb); | ||
| cls_str = PyObject_Str(tp); | ||
| cls_str = PyType_GetName((PyTypeObject *)tp); |
There was a problem hiding this comment.
I'm not sure it's guaranteed that tp is actually a type here, although of course it should be. Perhaps we can execute this block only if (PyType_Check(tb)).
There was a problem hiding this comment.
See https://docs.python.org/3/c-api/exceptions.html?highlight=pyerr_fetch#c.PyErr_Fetch, tp is guaranteed to be a typeobject here.
There was a problem hiding this comment.
There's no explicit statement that says that, and there is no check in the C code in errors.c that ensures that the type is really a type.
There was a problem hiding this comment.
Fair enough. Corrected 👍
|
Thanks @kamilturek for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
…resentation (pythonGH-98302) (cherry picked from commit b9dedfe) Co-authored-by: Kamil Turek <kamil.turek@hotmail.com>
|
GH-99234 is a backport of this pull request to the 3.11 branch. |
|
GH-99235 is a backport of this pull request to the 3.10 branch. |
…resentation (pythonGH-98302) (cherry picked from commit b9dedfe) Co-authored-by: Kamil Turek <kamil.turek@hotmail.com>
|
GH-99452 is a backport of this pull request to the 3.10 branch. |
…resentation (python#98302) (cherry picked from commit b9dedfe)
This PR updates the exception messages raised from
ctypescalls to print the exception class name instead of its string representation. Also, it removes obsoleteexceptions.prefixes from documentation examples.Closes #92119.