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

gh-107600: docs: Update ctypes.ArgumentError error message #107601

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:mod:`ctypes` exports the *cdll*, and on Windows *windll* and *oledll*
objects, for loading dynamic link libraries.

You load libraries by accessing them as attributes of these objects. *cdll*

Check warning on line 40 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:type reference target not found: HRESULT
loads libraries which export functions using the standard ``cdecl`` calling
convention, while *windll* libraries call functions using the ``stdcall``
calling convention. *oledll* also uses the ``stdcall`` calling convention, and
Expand Down Expand Up @@ -70,7 +70,7 @@
being used by Python. Where possible, use native Python functionality,
or else import and use the ``msvcrt`` module.

On Linux, it is required to specify the filename *including* the extension to

Check warning on line 73 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: LoadLibrary
load a library, so attribute access can not be used to load libraries. Either the
:meth:`LoadLibrary` method of the dll loaders should be used, or you should load
the library by creating an instance of CDLL by calling the constructor::
Expand Down Expand Up @@ -238,7 +238,7 @@
+----------------------+------------------------------------------+----------------------------+
| :class:`c_ulong` | :c:expr:`unsigned long` | int |
+----------------------+------------------------------------------+----------------------------+
| :class:`c_longlong` | :c:expr:`__int64` or :c:expr:`long long` | int |

Check warning on line 241 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

c:identifier reference target not found: __int64
+----------------------+------------------------------------------+----------------------------+
| :class:`c_ulonglong` | :c:expr:`unsigned __int64` or | int |
| | :c:expr:`unsigned long long` | |
Expand Down Expand Up @@ -333,7 +333,7 @@
10 b'Hi\x00lo\x00\x00\x00\x00\x00'
>>>

The :func:`create_string_buffer` function replaces the old :func:`c_buffer`

Check warning on line 336 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:func reference target not found: c_buffer
function (which is still available as an alias). To create a mutable memory
block containing unicode characters of the C type :c:type:`wchar_t`, use the
:func:`create_unicode_buffer` function.
Expand Down Expand Up @@ -361,7 +361,7 @@
>>> printf(b"%f bottles of beer\n", 42.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ArgumentError: argument 2: TypeError: Don't know how to convert parameter 2
ctypes.ArgumentError: argument 2: TypeError: Don't know how to convert parameter 2
>>>

As has been mentioned before, all Python types except integers, strings, and
Expand Down Expand Up @@ -399,7 +399,7 @@
Calling functions with your own custom data types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can also customize :mod:`ctypes` argument conversion to allow instances of

Check warning on line 402 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:attr reference target not found: _as_parameter_
your own classes be used as function arguments. :mod:`ctypes` looks for an
:attr:`_as_parameter_` attribute and uses this as the function argument. Of
course, it must be one of integer, string, or bytes::
Expand All @@ -414,7 +414,7 @@
19
>>>

If you don't want to store the instance's data in the :attr:`_as_parameter_`

Check warning on line 417 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:attr reference target not found: _as_parameter_
instance variable, you could define a :class:`property` which makes the
attribute available on request.

Expand All @@ -424,10 +424,10 @@
Specifying the required argument types (function prototypes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It is possible to specify the required argument types of functions exported from

Check warning on line 427 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:attr reference target not found: argtypes
DLLs by setting the :attr:`argtypes` attribute.

:attr:`argtypes` must be a sequence of C data types (the ``printf`` function is

Check warning on line 430 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:attr reference target not found: argtypes
probably not a good example here, because it takes a variable number and
different types of parameters depending on the format string, on the other hand
this is quite handy to experiment with this feature)::
Expand All @@ -444,13 +444,13 @@
>>> printf(b"%d %d %d", 1, 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ArgumentError: argument 2: TypeError: wrong type
ctypes.ArgumentError: argument 2: TypeError: 'int' object cannot be interpreted as ctypes.c_char_p
>>> printf(b"%s %d %f\n", b"X", 2, 3)
X 2 3.000000
13
>>>

If you have defined your own classes which you pass to function calls, you have

Check warning on line 453 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: from_param

Check warning on line 453 in Doc/library/ctypes.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:attr reference target not found: argtypes
to implement a :meth:`from_param` class method for them to be able to use them
in the :attr:`argtypes` sequence. The :meth:`from_param` class method receives
the Python object passed to the function call, it should do a typecheck or
Expand Down
Loading