Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ctypes: Improve error messages when converting to an incompatible type #107455

Closed
Labels
@tomasr8

Description

@tomasr8

This code produces an error with a somewhat unhelpful message:

fromctypesimport*printf=CDLL('libc.so.6').printfprintf.argtypes= [c_char_p,c_char_p]printf(b"Value %s\n",10)# call with an incompatible argument
Traceback (mostrecentcalllast):File"/home/tomas/dev/cpython/error.py",line5,in<module>printf(b"Value: %s\n",10)ctypes.ArgumentError:argument2:TypeError:wrongtype

The source code itself suggests providing a better message:

/* XXX better message */
PyErr_SetString(PyExc_TypeError,
"wrong type");

I suggest making the message more helpful by including the expected argument type and the type that was actually provided e.g.

- TypeError: wrong type+ TypeError: 'int' object cannot be interpreted as ctypes.c_char_p

The same improvement can be applied toc_wchar_p andc_void_p.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp