@@ -17,26 +17,12 @@ of Unicode characters while staying memory efficient. There are special cases
17
17
for strings where all code points are below 128, 256, or 65536; otherwise, code
18
18
points must be below 1114112 (which is the full Unicode range).
19
19
20
- :c:type: `Py_UNICODE* ` and UTF-8 representations are created on demand and cached
21
- in the Unicode object. The :c:type: `Py_UNICODE* ` representation is deprecated
22
- and inefficient.
23
-
24
- Due to the transition between the old APIs and the new APIs, Unicode objects
25
- can internally be in two states depending on how they were created:
26
-
27
- * "canonical" Unicode objects are all objects created by a non-deprecated
28
- Unicode API. They use the most efficient representation allowed by the
29
- implementation.
30
-
31
- * "legacy" Unicode objects have been created through one of the deprecated
32
- APIs (typically :c:func: `PyUnicode_FromUnicode `) and only bear the
33
- :c:type: `Py_UNICODE* ` representation; you will have to call
34
- :c:func: `PyUnicode_READY ` on them before calling any other API.
20
+ UTF-8 representation is created on demand and cached in the Unicode object.
35
21
36
22
.. note ::
37
- The "legacy" Unicode object will be removed in Python 3.12 with deprecated
38
- APIs. All Unicode objects will be "canonical" since then. See :pep: ` 623 `
39
- for more information.
23
+ The :c:type: ` Py_UNICODE ` representation has been removed since Python 3.12
24
+ with deprecated APIs.
25
+ See :pep: ` 623 ` for more information.
40
26
41
27
42
28
Unicode Type
@@ -101,18 +87,12 @@ access to internal read-only data of Unicode objects:
101
87
102
88
.. c :function :: int PyUnicode_READY (PyObject *o)
103
89
104
- Ensure the string object *o * is in the "canonical" representation. This is
105
- required before using any of the access macros described below.
106
-
107
- .. XXX expand on when it is not required
108
-
109
- Returns ``0 `` on success and ``-1 `` with an exception set on failure, which in
110
- particular happens if memory allocation fails.
90
+ Returns ``0 ``. This API is kept only for backward compatibility.
111
91
112
92
.. versionadded :: 3.3
113
93
114
- .. deprecated-removed :: 3.10 3.12
115
- This API will be removed with :c:func: ` PyUnicode_FromUnicode ` .
94
+ .. deprecated :: 3.10
95
+ This API do nothing since Python 3.12. Please remove code using this function .
116
96
117
97
118
98
.. c :function :: Py_ssize_t PyUnicode_GET_LENGTH (PyObject *o)
@@ -130,23 +110,21 @@ access to internal read-only data of Unicode objects:
130
110
Return a pointer to the canonical representation cast to UCS1, UCS2 or UCS4
131
111
integer types for direct character access. No checks are performed if the
132
112
canonical representation has the correct character size; use
133
- :c:func: `PyUnicode_KIND ` to select the right function. Make sure
134
- :c:func: `PyUnicode_READY ` has been called before accessing this.
113
+ :c:func: `PyUnicode_KIND ` to select the right function.
135
114
136
115
.. versionadded :: 3.3
137
116
138
117
139
- .. c :macro :: PyUnicode_WCHAR_KIND
140
- PyUnicode_1BYTE_KIND
118
+ .. c :macro :: PyUnicode_1BYTE_KIND
141
119
PyUnicode_2BYTE_KIND
142
120
PyUnicode_4BYTE_KIND
143
121
144
122
Return values of the :c:func: `PyUnicode_KIND ` macro.
145
123
146
124
.. versionadded :: 3.3
147
125
148
- .. deprecated-removed :: 3.10 3.12
149
- ``PyUnicode_WCHAR_KIND `` is deprecated .
126
+ .. versionchanged :: 3.12
127
+ ``PyUnicode_WCHAR_KIND `` has been removed .
150
128
151
129
152
130
.. c :function :: int PyUnicode_KIND (PyObject *o)
@@ -155,8 +133,6 @@ access to internal read-only data of Unicode objects:
155
133
bytes per character this Unicode object uses to store its data. *o* has to
156
134
be a Unicode object in the "canonical" representation (not checked).
157
135
158
- .. XXX document "0" return value?
159
-
160
136
.. versionadded:: 3.3
161
137
162
138
@@ -208,49 +184,6 @@ access to internal read-only data of Unicode objects:
208
184
.. versionadded :: 3.3
209
185
210
186
211
- .. c :function :: Py_ssize_t PyUnicode_GET_SIZE (PyObject *o)
212
-
213
- Return the size of the deprecated :c:type: `Py_UNICODE ` representation, in
214
- code units (this includes surrogate pairs as 2 units). *o* has to be a
215
- Unicode object (not checked).
216
-
217
- .. deprecated-removed:: 3.3 3.12
218
- Part of the old-style Unicode API, please migrate to using
219
- :c:func:`PyUnicode_GET_LENGTH`.
220
-
221
-
222
- .. c:function:: Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *o)
223
-
224
- Return the size of the deprecated :c:type: `Py_UNICODE ` representation in
225
- bytes. *o * has to be a Unicode object (not checked).
226
-
227
- .. deprecated-removed:: 3.3 3.12
228
- Part of the old-style Unicode API, please migrate to using
229
- :c:func:`PyUnicode_GET_LENGTH`.
230
-
231
-
232
- .. c:function:: Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *o)
233
- const char * PyUnicode_AS_DATA(PyObject *o)
234
-
235
- Return a pointer to a :c:type: `Py_UNICODE ` representation of the object. The
236
- returned buffer is always terminated with an extra null code point. It
237
- may also contain embedded null code points, which would cause the string
238
- to be truncated when used in most C functions. The ``AS_DATA `` form
239
- casts the pointer to :c:type: `const char * `. The *o * argument has to be
240
- a Unicode object (not checked).
241
-
242
- .. versionchanged:: 3.3
243
- This function is now inefficient -- because in many cases the
244
- :c:type:`Py_UNICODE` representation does not exist and needs to be created
245
- -- and can fail (return ``NULL `` with an exception set). Try to port the
246
- code to use the new :c:func:`PyUnicode_nBYTE_DATA` macros or use
247
- :c:func:`PyUnicode_WRITE` or :c:func:`PyUnicode_READ`.
248
-
249
- .. deprecated-removed:: 3.3 3.12
250
- Part of the old-style Unicode API, please migrate to using the
251
- :c:func:`PyUnicode_nBYTE_DATA` family of macros.
252
-
253
-
254
187
.. c :function :: int PyUnicode_IsIdentifier (PyObject *o)
255
188
256
189
Return ``1 `` if the string is a valid identifier according to the language
@@ -436,12 +369,17 @@ APIs:
436
369
437
370
Create a Unicode object from the char buffer *u *. The bytes will be
438
371
interpreted as being UTF-8 encoded. The buffer is copied into the new
439
- object. If the buffer is not ``NULL ``, the return value might be a shared
440
- object, i.e. modification of the data is not allowed.
372
+ object.
373
+ The return value might be a shared object, i.e. modification of the data is
374
+ not allowed.
441
375
442
- If *u * is ``NULL ``, this function behaves like :c:func: `PyUnicode_FromUnicode `
443
- with the buffer set to ``NULL ``. This usage is deprecated in favor of
444
- :c:func: `PyUnicode_New `, and will be removed in Python 3.12.
376
+ This function raises :exc: `SystemError ` when:
377
+
378
+ * *size * < 0,
379
+ * *u * is ``NULL `` and *size * > 0
380
+
381
+ .. versionchanged :: 3.12
382
+ *u * == ``NULL `` with *size * > 0 is not allowed anymore.
445
383
446
384
447
385
.. c :function :: PyObject *PyUnicode_FromString (const char *u)
@@ -680,79 +618,6 @@ APIs:
680
618
.. versionadded :: 3.3
681
619
682
620
683
- Deprecated Py_UNICODE APIs
684
- """"""""""""""""""""""""""
685
-
686
- .. deprecated-removed :: 3.3 3.12
687
-
688
- These API functions are deprecated with the implementation of :pep: `393 `.
689
- Extension modules can continue using them, as they will not be removed in Python
690
- 3.x, but need to be aware that their use can now cause performance and memory hits.
691
-
692
-
693
- .. c :function :: PyObject* PyUnicode_FromUnicode (const Py_UNICODE *u, Py_ssize_t size)
694
-
695
- Create a Unicode object from the Py_UNICODE buffer *u * of the given size. *u *
696
- may be ``NULL `` which causes the contents to be undefined. It is the user's
697
- responsibility to fill in the needed data. The buffer is copied into the new
698
- object.
699
-
700
- If the buffer is not ``NULL ``, the return value might be a shared object.
701
- Therefore, modification of the resulting Unicode object is only allowed when
702
- *u * is ``NULL ``.
703
-
704
- If the buffer is ``NULL ``, :c:func: `PyUnicode_READY ` must be called once the
705
- string content has been filled before using any of the access macros such as
706
- :c:func: `PyUnicode_KIND `.
707
-
708
- .. deprecated-removed :: 3.3 3.12
709
- Part of the old-style Unicode API, please migrate to using
710
- :c:func: `PyUnicode_FromKindAndData `, :c:func: `PyUnicode_FromWideChar `, or
711
- :c:func: `PyUnicode_New `.
712
-
713
-
714
- .. c :function :: Py_UNICODE* PyUnicode_AsUnicode (PyObject *unicode)
715
-
716
- Return a read-only pointer to the Unicode object's internal
717
- :c:type: `Py_UNICODE ` buffer, or ``NULL `` on error. This will create the
718
- :c:type: `Py_UNICODE* ` representation of the object if it is not yet
719
- available. The buffer is always terminated with an extra null code point.
720
- Note that the resulting :c:type: `Py_UNICODE ` string may also contain
721
- embedded null code points, which would cause the string to be truncated when
722
- used in most C functions.
723
-
724
- .. deprecated-removed :: 3.3 3.12
725
- Part of the old-style Unicode API, please migrate to using
726
- :c:func: `PyUnicode_AsUCS4 `, :c:func: `PyUnicode_AsWideChar `,
727
- :c:func: `PyUnicode_ReadChar ` or similar new APIs.
728
-
729
-
730
- .. c :function :: Py_UNICODE* PyUnicode_AsUnicodeAndSize (PyObject *unicode, Py_ssize_t *size)
731
-
732
- Like :c:func: `PyUnicode_AsUnicode `, but also saves the :c:func: `Py_UNICODE `
733
- array length (excluding the extra null terminator) in *size*.
734
- Note that the resulting :c:type:`Py_UNICODE*` string
735
- may contain embedded null code points, which would cause the string to be
736
- truncated when used in most C functions.
737
-
738
- .. versionadded:: 3.3
739
-
740
- .. deprecated-removed:: 3.3 3.12
741
- Part of the old-style Unicode API, please migrate to using
742
- :c:func:`PyUnicode_AsUCS4`, :c:func:`PyUnicode_AsWideChar`,
743
- :c:func:`PyUnicode_ReadChar` or similar new APIs.
744
-
745
-
746
- .. c:function:: Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
747
-
748
- Return the size of the deprecated :c:type: `Py_UNICODE ` representation, in
749
- code units (this includes surrogate pairs as 2 units).
750
-
751
- .. deprecated-removed:: 3.3 3.12
752
- Part of the old-style Unicode API, please migrate to using
753
- :c:func:`PyUnicode_GET_LENGTH`.
754
-
755
-
756
621
.. c :function :: PyObject* PyUnicode_FromObject (PyObject *obj)
757
622
758
623
Copy an instance of a Unicode subtype to a new true Unicode object if
0 commit comments