Skip to content

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

@chgnrdv

Description

@chgnrdv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions