[New-bugs-announce] [issue35874] Clarify that the (...) convertor to PyArg_ParseTuple... accepts any sequence.

Antony Lee report at bugs.python.org
Fri Feb 1 04:03:29 EST 2019


New submission from Antony Lee <anntzer.lee at gmail.com>:

The documentation for the accepted types for each format unit in PyArg_ParseTuple (and its variants) is usually quite detailed; compare for example

    y* (bytes-like object) [Py_buffer]
    This variant on s* doesn’t accept Unicode objects, only bytes-like objects. This is the recommended way to accept binary data.

and

    S (bytes) [PyBytesObject *]
    Requires that the Python object is a bytes object, without attempting any conversion. Raises TypeError if the object is not a bytes object. The C variable may also be declared as PyObject*.

There, the type in parenthesis (which is explained as "the entry in (round) parentheses is the Python object type that matches the format unit") differentiates between "bytes-like object" and "bytes".

However, the documentation for "(...)" is a bit more confusing:

    (items) (tuple) [matching-items]
    The object must be a Python sequence whose length is the number of format units in items. The C arguments must correspond to the individual format units in items. Format units for sequences may be nested.

The type in parenthesis is "tuple" (exactly), but the paragraph says "sequence".  The actual behavior appears indeed to be that any sequence (e.g., list, numpy array) is accepted, so I'd suggest changing the type in the parenthesis to "sequence".

----------
assignee: docs at python
components: Documentation
messages: 334660
nosy: Antony.Lee, docs at python
priority: normal
severity: normal
status: open
title: Clarify that the (...) convertor to PyArg_ParseTuple... accepts any sequence.

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35874>
_______________________________________


More information about the New-bugs-announce mailing list