This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Clarify that the (...) convertor to PyArg_ParseTuple... accepts any sequence.
Type: Stage:
Components: Documentation Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Antony.Lee, docs@python, serhiy.storchaka
Priority: normal Keywords:

Created on 2019-02-01 09:03 by Antony.Lee, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg334660 - (view) Author: Antony Lee (Antony.Lee) * Date: 2019-02-01 09:03
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".
msg335546 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-02-14 16:59
Passing non-tuple can lead to reference counting error. See issue6083. I think that accepting a non-tuple should be deprecated, and finally disallowed.
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 80055
2019-02-14 16:59:26serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg335546
2019-02-01 09:03:29Antony.Leecreate