Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ctypes_extend_error prints exception class string representation instead of exception class name #92119

Closed
chgnrdv opened this issue May 1, 2022 · 0 comments · Fixed by #98302
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented May 1, 2022

Example:

>>> import ctypes
>>> lib = ctypes.CDLL("some_dll")
>>> lib.c_function.argtypes = [ctypes.c_char_p, ctypes.c_int]
>>> lib.c_function(123, "Foobar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

Expected behavior is to print exception name ("TypeError") as stated in documentation:
https://github.com/python/cpython/blob/main/Doc/library/ctypes.rst#specifying-the-required-argument-types-function-prototypes

Possible solution is to use PyType_GetName instead of PyObject_Str at

cls_str = PyObject_Str(tp);

but I'm not sure how to draw it up correctly.

@chgnrdv chgnrdv added the type-bug An unexpected behavior, bug, or error label May 1, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2022
…resentation (pythonGH-98302)

(cherry picked from commit b9dedfe)

Co-authored-by: Kamil Turek <kamil.turek@hotmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2022
…resentation (pythonGH-98302)

(cherry picked from commit b9dedfe)

Co-authored-by: Kamil Turek <kamil.turek@hotmail.com>
miss-islington added a commit that referenced this issue Nov 8, 2022
…ation (GH-98302)

(cherry picked from commit b9dedfe)

Co-authored-by: Kamil Turek <kamil.turek@hotmail.com>
kamilturek added a commit to kamilturek/cpython that referenced this issue Nov 13, 2022
JelleZijlstra pushed a commit that referenced this issue Nov 13, 2022
…presentation (GH-98302) (#99452)

gh-92119: ctypes: Print exception class name instead of its representation (#98302)

(cherry picked from commit b9dedfe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants