@@ -55,13 +55,11 @@ which disallows mutable objects such as :class:`bytearray`.
5555
5656.. note ::
5757
58- For all ``# `` variants of formats (``s# ``, ``y# ``, etc.), the type of
59- the length argument (int or :c:type: `Py_ssize_t `) is controlled by
60- defining the macro :c:macro: `PY_SSIZE_T_CLEAN ` before including
61- :file: `Python.h `. If the macro was defined, length is a
62- :c:type: `Py_ssize_t ` rather than an :c:type: `int `. This behavior will change
63- in a future Python version to only support :c:type: `Py_ssize_t ` and
64- drop :c:type: `int ` support. It is best to always define :c:macro: `PY_SSIZE_T_CLEAN `.
58+ For all ``# `` variants of formats (``s# ``, ``y# ``, etc.), the macro
59+ :c:macro: `PY_SSIZE_T_CLEAN ` must be defined before including
60+ :file: `Python.h `. On Python 3.9 and older, the type of the length argument
61+ is :c:type: `Py_ssize_t ` if the :c:macro: `PY_SSIZE_T_CLEAN ` macro is defined,
62+ or int otherwise.
6563
6664
6765``s `` (:class: `str `) [const char \* ]
@@ -90,7 +88,7 @@ which disallows mutable objects such as :class:`bytearray`.
9088 In this case the resulting C string may contain embedded NUL bytes.
9189 Unicode objects are converted to C strings using ``'utf-8' `` encoding.
9290
93- ``s# `` (:class: `str `, read-only :term: `bytes-like object `) [const char \* , int or :c:type: `Py_ssize_t `]
91+ ``s# `` (:class: `str `, read-only :term: `bytes-like object `) [const char \* , :c:type: `Py_ssize_t `]
9492 Like ``s* ``, except that it doesn't accept mutable objects.
9593 The result is stored into two C variables,
9694 the first one a pointer to a C string, the second one its length.
@@ -105,7 +103,7 @@ which disallows mutable objects such as :class:`bytearray`.
105103 Like ``s* ``, but the Python object may also be ``None ``, in which case the
106104 ``buf `` member of the :c:type: `Py_buffer ` structure is set to ``NULL ``.
107105
108- ``z# `` (:class: `str `, read-only :term: `bytes-like object ` or ``None ``) [const char \* , int or :c:type: `Py_ssize_t `]
106+ ``z# `` (:class: `str `, read-only :term: `bytes-like object ` or ``None ``) [const char \* , :c:type: `Py_ssize_t `]
109107 Like ``s# ``, but the Python object may also be ``None ``, in which case the C
110108 pointer is set to ``NULL ``.
111109
@@ -124,7 +122,7 @@ which disallows mutable objects such as :class:`bytearray`.
124122 bytes-like objects. **This is the recommended way to accept
125123 binary data. **
126124
127- ``y# `` (read-only :term: `bytes-like object `) [const char \* , int or :c:type: `Py_ssize_t `]
125+ ``y# `` (read-only :term: `bytes-like object `) [const char \* , :c:type: `Py_ssize_t `]
128126 This variant on ``s# `` doesn't accept Unicode objects, only bytes-like
129127 objects.
130128
@@ -155,7 +153,7 @@ which disallows mutable objects such as :class:`bytearray`.
155153 Part of the old-style :c:type: `Py_UNICODE ` API; please migrate to using
156154 :c:func: `PyUnicode_AsWideCharString `.
157155
158- ``u# `` (:class: `str `) [const Py_UNICODE \* , int or :c:type: `Py_ssize_t `]
156+ ``u# `` (:class: `str `) [const Py_UNICODE \* , :c:type: `Py_ssize_t `]
159157 This variant on ``u `` stores into two C variables, the first one a pointer to a
160158 Unicode data buffer, the second one its length. This variant allows
161159 null code points.
@@ -172,7 +170,7 @@ which disallows mutable objects such as :class:`bytearray`.
172170 Part of the old-style :c:type: `Py_UNICODE ` API; please migrate to using
173171 :c:func: `PyUnicode_AsWideCharString `.
174172
175- ``Z# `` (:class: `str ` or ``None ``) [const Py_UNICODE \* , int or :c:type: `Py_ssize_t `]
173+ ``Z# `` (:class: `str ` or ``None ``) [const Py_UNICODE \* , :c:type: `Py_ssize_t `]
176174 Like ``u# ``, but the Python object may also be ``None ``, in which case the
177175 :c:type: `Py_UNICODE ` pointer is set to ``NULL ``.
178176
@@ -213,7 +211,7 @@ which disallows mutable objects such as :class:`bytearray`.
213211 recoding them. Instead, the implementation assumes that the byte string object uses
214212 the encoding passed in as parameter.
215213
216- ``es# `` (:class: `str `) [const char \* encoding, char \*\* buffer, int or :c:type: `Py_ssize_t ` \* buffer_length]
214+ ``es# `` (:class: `str `) [const char \* encoding, char \*\* buffer, :c:type: `Py_ssize_t ` \* buffer_length]
217215 This variant on ``s# `` is used for encoding Unicode into a character buffer.
218216 Unlike the ``es `` format, this variant allows input data which contains NUL
219217 characters.
@@ -244,7 +242,7 @@ which disallows mutable objects such as :class:`bytearray`.
244242 In both cases, *\* buffer_length * is set to the length of the encoded data
245243 without the trailing NUL byte.
246244
247- ``et# `` (:class: `str `, :class: `bytes ` or :class: `bytearray `) [const char \* encoding, char \*\* buffer, int or :c:type: `Py_ssize_t ` \* buffer_length]
245+ ``et# `` (:class: `str `, :class: `bytes ` or :class: `bytearray `) [const char \* encoding, char \*\* buffer, :c:type: `Py_ssize_t ` \* buffer_length]
248246 Same as ``es# `` except that byte string objects are passed through without recoding
249247 them. Instead, the implementation assumes that the byte string object uses the
250248 encoding passed in as parameter.
@@ -549,7 +547,7 @@ Building values
549547 Convert a null-terminated C string to a Python :class:`str` object using ``'utf-8'``
550548 encoding. If the C string pointer is ``NULL``, ``None`` is used.
551549
552- ``s#`` (:class:`str` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`]
550+ ``s#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ssize_t`]
553551 Convert a C string and its length to a Python :class:`str` object using ``' utf-8' ``
554552 encoding. If the C string pointer is ``NULL ``, the length is ignored and
555553 ``None`` is returned.
@@ -558,30 +556,30 @@ Building values
558556 This converts a C string to a Python :class:`bytes` object. If the C
559557 string pointer is ``NULL``, ``None`` is returned.
560558
561- ``y#`` (:class:`bytes`) [const char \*, int or :c:type:`Py_ssize_t`]
559+ ``y#`` (:class:`bytes`) [const char \*, :c:type:`Py_ssize_t`]
562560 This converts a C string and its lengths to a Python object. If the C
563561 string pointer is ``NULL ``, ``None`` is returned.
564562
565563 ``z `` (:class: `str ` or ``None ``) [const char \*]
566564 Same as ``s``.
567565
568- ``z#`` (:class:`str` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`]
566+ ``z#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ssize_t`]
569567 Same as ``s#``.
570568
571569 ``u `` (:class: `str `) [const wchar_t \*]
572570 Convert a null-terminated :c:type:`wchar_t` buffer of Unicode (UTF-16 or UCS-4)
573571 data to a Python Unicode object. If the Unicode buffer pointer is ``NULL``,
574572 ``None`` is returned.
575573
576- ``u#`` (:class:`str`) [const wchar_t \*, int or :c:type:`Py_ssize_t`]
574+ ``u#`` (:class:`str`) [const wchar_t \*, :c:type:`Py_ssize_t`]
577575 Convert a Unicode (UTF-16 or UCS-4) data buffer and its length to a Python
578576 Unicode object. If the Unicode buffer pointer is ``NULL``, the length is ignored
579577 and ``None`` is returned.
580578
581579 ``U`` (:class: `str ` or ``None ``) [const char \*]
582580 Same as ``s``.
583581
584- ``U#`` (:class:`str` or ``None``) [const char \*, int or :c:type:`Py_ssize_t`]
582+ ``U#`` (:class:`str` or ``None``) [const char \*, :c:type:`Py_ssize_t`]
585583 Same as ``s#``.
586584
587585 ``i `` (:class: `int `) [int]
0 commit comments