@@ -55,13 +55,11 @@ which disallows mutable objects such as :class:`bytearray`.
55
55
56
56
.. note ::
57
57
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.
65
63
66
64
67
65
``s `` (:class: `str `) [const char \* ]
@@ -90,7 +88,7 @@ which disallows mutable objects such as :class:`bytearray`.
90
88
In this case the resulting C string may contain embedded NUL bytes.
91
89
Unicode objects are converted to C strings using ``'utf-8' `` encoding.
92
90
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 `]
94
92
Like ``s* ``, except that it doesn't accept mutable objects.
95
93
The result is stored into two C variables,
96
94
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`.
105
103
Like ``s* ``, but the Python object may also be ``None ``, in which case the
106
104
``buf `` member of the :c:type: `Py_buffer ` structure is set to ``NULL ``.
107
105
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 `]
109
107
Like ``s# ``, but the Python object may also be ``None ``, in which case the C
110
108
pointer is set to ``NULL ``.
111
109
@@ -124,7 +122,7 @@ which disallows mutable objects such as :class:`bytearray`.
124
122
bytes-like objects. **This is the recommended way to accept
125
123
binary data. **
126
124
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 `]
128
126
This variant on ``s# `` doesn't accept Unicode objects, only bytes-like
129
127
objects.
130
128
@@ -155,7 +153,7 @@ which disallows mutable objects such as :class:`bytearray`.
155
153
Part of the old-style :c:type: `Py_UNICODE ` API; please migrate to using
156
154
:c:func: `PyUnicode_AsWideCharString `.
157
155
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 `]
159
157
This variant on ``u `` stores into two C variables, the first one a pointer to a
160
158
Unicode data buffer, the second one its length. This variant allows
161
159
null code points.
@@ -172,7 +170,7 @@ which disallows mutable objects such as :class:`bytearray`.
172
170
Part of the old-style :c:type: `Py_UNICODE ` API; please migrate to using
173
171
:c:func: `PyUnicode_AsWideCharString `.
174
172
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 `]
176
174
Like ``u# ``, but the Python object may also be ``None ``, in which case the
177
175
:c:type: `Py_UNICODE ` pointer is set to ``NULL ``.
178
176
@@ -213,7 +211,7 @@ which disallows mutable objects such as :class:`bytearray`.
213
211
recoding them. Instead, the implementation assumes that the byte string object uses
214
212
the encoding passed in as parameter.
215
213
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]
217
215
This variant on ``s# `` is used for encoding Unicode into a character buffer.
218
216
Unlike the ``es `` format, this variant allows input data which contains NUL
219
217
characters.
@@ -244,7 +242,7 @@ which disallows mutable objects such as :class:`bytearray`.
244
242
In both cases, *\* buffer_length * is set to the length of the encoded data
245
243
without the trailing NUL byte.
246
244
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]
248
246
Same as ``es# `` except that byte string objects are passed through without recoding
249
247
them. Instead, the implementation assumes that the byte string object uses the
250
248
encoding passed in as parameter.
@@ -549,7 +547,7 @@ Building values
549
547
Convert a null-terminated C string to a Python :class:`str` object using ``'utf-8'``
550
548
encoding. If the C string pointer is ``NULL``, ``None`` is used.
551
549
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`]
553
551
Convert a C string and its length to a Python :class:`str` object using ``' utf-8' ``
554
552
encoding. If the C string pointer is ``NULL ``, the length is ignored and
555
553
``None`` is returned.
@@ -558,30 +556,30 @@ Building values
558
556
This converts a C string to a Python :class:`bytes` object. If the C
559
557
string pointer is ``NULL``, ``None`` is returned.
560
558
561
- ``y#`` (:class:`bytes`) [const char \*, int or :c:type:`Py_ssize_t`]
559
+ ``y#`` (:class:`bytes`) [const char \*, :c:type:`Py_ssize_t`]
562
560
This converts a C string and its lengths to a Python object. If the C
563
561
string pointer is ``NULL ``, ``None`` is returned.
564
562
565
563
``z `` (:class: `str ` or ``None ``) [const char \*]
566
564
Same as ``s``.
567
565
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`]
569
567
Same as ``s#``.
570
568
571
569
``u `` (:class: `str `) [const wchar_t \*]
572
570
Convert a null-terminated :c:type:`wchar_t` buffer of Unicode (UTF-16 or UCS-4)
573
571
data to a Python Unicode object. If the Unicode buffer pointer is ``NULL``,
574
572
``None`` is returned.
575
573
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`]
577
575
Convert a Unicode (UTF-16 or UCS-4) data buffer and its length to a Python
578
576
Unicode object. If the Unicode buffer pointer is ``NULL``, the length is ignored
579
577
and ``None`` is returned.
580
578
581
579
``U`` (:class: `str ` or ``None ``) [const char \*]
582
580
Same as ``s``.
583
581
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`]
585
583
Same as ``s#``.
586
584
587
585
``i `` (:class: `int `) [int]
0 commit comments