gh-50333: Deprecate support of non-tuple sequences in PyArg_ParseTuple() (GH-128374)

Non-tuple sequences are deprecated as argument for the "(items)" format unit
in PyArg_ParseTuple() and other argument parsing functions if items contains
format units which store borrowed buffer or reference (e.g. "s" and "O").

str and bytearray are no longer accepted as valid sequences.
This commit is contained in:
Serhiy Storchaka 2025-04-08 14:26:32 +03:00 committed by GitHub
parent 0f04f2456a
commit 0e4cf9ce7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 150 additions and 29 deletions

View file

@ -357,11 +357,26 @@ Other objects
.. versionadded:: 3.3
``(items)`` (:class:`tuple`) [*matching-items*]
The object must be a Python sequence whose length is the number of format units
``(items)`` (sequence) [*matching-items*]
The object must be a Python sequence (except :class:`str`, :class:`bytes`
or :class:`bytearray`) 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.
If *items* contains format units which store a :ref:`borrowed buffer
<c-arg-borrowed-buffer>` (``s``, ``s#``, ``z``, ``z#``, ``y``, or ``y#``)
or a :term:`borrowed reference` (``S``, ``Y``, ``U``, ``O``, or ``O!``),
the object must be a Python tuple.
The *converter* for the ``O&`` format unit in *items* must not store
a borrowed buffer or a borrowed reference.
.. versionchanged:: next
:class:`str` and :class:`bytearray` objects no longer accepted as a sequence.
.. deprecated:: next
Non-tuple sequences are deprecated if *items* contains format units
which store a borrowed buffer or a borrowed reference.
A few other characters have a meaning in a format string. These may not occur
inside nested parentheses. They are: