Skip to content

Commit 115765c

Browse files
committed
Move soft-deprecated API to the "Deprecated API" section
1 parent eb77b4b commit 115765c

1 file changed

Lines changed: 151 additions & 151 deletions

File tree

‎Doc/c-api/unicode.rst‎

Lines changed: 151 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,6 @@ access to internal read-only data of Unicode objects:
154154
.. versionadded:: 3.3
155155
156156
157-
.. c:function:: void PyUnicode_WRITE(int kind, void *data, \
158-
Py_ssize_t index, Py_UCS4 value)
159-
160-
Write the code point *value* to the given zero-based *index* in a string.
161-
162-
The *kind* value and *data* pointer must have been obtained from a
163-
string using :c:func:`PyUnicode_KIND` and :c:func:`PyUnicode_DATA`
164-
respectively. You must hold a reference to that string while calling
165-
:c:func:`!PyUnicode_WRITE`. All requirements of
166-
:c:func:`PyUnicode_WriteChar` also apply.
167-
168-
The function performs no checks for any of its requirements,
169-
and is intended for usage in loops.
170-
171-
While :class:`str` objects are usually immutable in Python, this special C API allows
172-
mutating a fresh :class:`str` object if the string has not been "used" yet.
173-
174-
.. versionadded:: 3.3
175-
176-
.. soft-deprecated:: next
177-
Use the :c:type:`PyUnicodeWriter` API instead.
178-
179-
180157
.. c:function:: Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)
181158
182159
Read a code point from a canonical representation *data* (as obtained with
@@ -385,44 +362,6 @@ Creating and accessing Unicode strings
385362
To create Unicode objects and access their basic sequence properties, use these
386363
APIs:
387364
388-
.. c:function:: PyObject* PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
389-
390-
Create a new Unicode object. *maxchar* should be the true maximum code point
391-
to be placed in the string. As an approximation, it can be rounded up to the
392-
nearest value in the sequence 127, 255, 65535, 1114111.
393-
394-
On error, set an exception and return ``NULL``.
395-
396-
After creation, the string can be filled by :c:func:`PyUnicode_WriteChar`,
397-
:c:func:`PyUnicode_CopyCharacters`, :c:func:`PyUnicode_Fill`,
398-
:c:func:`PyUnicode_WRITE` or similar.
399-
Since strings are supposed to be immutable, take care to not “use” the
400-
result while it is being modified. In particular, before it's filled
401-
with its final contents, a string:
402-
403-
- must not be hashed,
404-
- must not be :c:func:`converted to UTF-8 <PyUnicode_AsUTF8AndSize>`,
405-
or another non-"canonical" representation,
406-
- must not have its reference count changed,
407-
- must not be shared with code that might do one of the above.
408-
409-
This list is not exhaustive. Avoiding these uses is your responsibility;
410-
Python does not always check these requirements.
411-
412-
To avoid accidentally exposing a partially-written string object, prefer
413-
using the :c:type:`PyUnicodeWriter` API, or one of the ``PyUnicode_From*``
414-
functions below.
415-
416-
While :class:`str` objects are usually immutable in Python, this special C API
417-
returns a :class:`str` object that can be mutated, except if *size* is zero, in which
418-
case it returns the immutable empty string constant.
419-
420-
.. versionadded:: 3.3
421-
422-
.. soft-deprecated:: next
423-
Use the :c:type:`PyUnicodeWriter` API instead.
424-
425-
426365
.. c:function:: PyObject* PyUnicode_FromKindAndData(int kind, const void *buffer, \
427366
Py_ssize_t size)
428367
@@ -755,96 +694,6 @@ APIs:
755694
.. versionadded:: 3.3
756695
757696
758-
.. c:function:: Py_ssize_t PyUnicode_CopyCharacters(PyObject *to, \
759-
Py_ssize_t to_start, \
760-
PyObject *from, \
761-
Py_ssize_t from_start, \
762-
Py_ssize_t how_many)
763-
764-
Copy characters from one Unicode object into another. This function performs
765-
character conversion when necessary and falls back to :c:func:`!memcpy` if
766-
possible. Returns ``-1`` and sets an exception on error, otherwise returns
767-
the number of copied characters.
768-
769-
While :class:`str` objects are usually immutable in Python, this special C API allows
770-
mutating a fresh :class:`str` object if the string has not been "used" yet.
771-
772-
See :c:func:`PyUnicode_New` for details.
773-
774-
.. versionadded:: 3.3
775-
776-
.. soft-deprecated:: next
777-
Use the :c:type:`PyUnicodeWriter` API instead.
778-
779-
780-
.. c:function:: int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length);
781-
782-
Resize a Unicode object *\*unicode* to the new *length* in code points.
783-
784-
Try to resize the string in place (which is usually faster than allocating
785-
a new string and copying characters), or create a new string.
786-
787-
*\*unicode* is modified to point to the new (resized) object and ``0`` is
788-
returned on success. Otherwise, ``-1`` is returned and an exception is set,
789-
and *\*unicode* is left untouched.
790-
791-
The function doesn't check string content, the result may not be a
792-
string in canonical representation.
793-
794-
While :class:`str` objects are usually immutable in Python, this special C API
795-
can resize a :class:`str` object in-place if the string has not been "used" yet.
796-
It returns a :class:`str` object which can be mutated, except if *size* is zero, in
797-
which case it returns the immutable empty string constant.
798-
799-
.. soft-deprecated:: next
800-
Use the :c:type:`PyUnicodeWriter` API instead.
801-
802-
803-
.. c:function:: Py_ssize_t PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, \
804-
Py_ssize_t length, Py_UCS4 fill_char)
805-
806-
Fill a string with a character: write *fill_char* into
807-
``unicode[start:start+length]``.
808-
809-
Fail if *fill_char* is bigger than the string maximum character, or if the
810-
string has more than 1 reference.
811-
812-
Return the number of written characters, or return ``-1`` and raise an
813-
exception on error.
814-
815-
While :class:`str` objects are usually immutable in Python, this special C API allows
816-
mutating a fresh :class:`str` object if the string has not been "used" yet.
817-
818-
See :c:func:`PyUnicode_New` for details.
819-
820-
.. versionadded:: 3.3
821-
822-
.. soft-deprecated:: next
823-
Use the :c:type:`PyUnicodeWriter` API instead.
824-
825-
826-
.. c:function:: int PyUnicode_WriteChar(PyObject *unicode, Py_ssize_t index, \
827-
Py_UCS4 character)
828-
829-
Write a *character* to the string *unicode* at the zero-based *index*.
830-
Return ``0`` on success, ``-1`` on error with an exception set.
831-
832-
This function checks that *unicode* is a Unicode object, that the index is
833-
not out of bounds, and that the object's reference count is one.
834-
See :c:func:`PyUnicode_WRITE` for a version that skips these checks,
835-
making them your responsibility.
836-
837-
While :class:`str` objects are usually immutable in Python, this special C API allows
838-
mutating a fresh :class:`str` object if the string has not been "used" yet.
839-
840-
See :c:func:`PyUnicode_New` for details.
841-
842-
.. versionadded:: 3.3
843-
844-
.. soft-deprecated:: next
845-
Use the :c:type:`PyUnicodeWriter` API instead.
846-
847-
848697
.. c:function:: Py_UCS4 PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index)
849698
850699
Read a character from a string. This function checks that *unicode* is a
@@ -2053,3 +1902,154 @@ The following API is deprecated.
20531902
This API does nothing since Python 3.12.
20541903
Previously, this could be called to check if
20551904
:c:func:`PyUnicode_READY` is necessary.
1905+
1906+
1907+
.. c:function:: PyObject* PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
1908+
1909+
Create a new Unicode object. *maxchar* should be the true maximum code point
1910+
to be placed in the string. As an approximation, it can be rounded up to the
1911+
nearest value in the sequence 127, 255, 65535, 1114111.
1912+
1913+
On error, set an exception and return ``NULL``.
1914+
1915+
After creation, the string can be filled by :c:func:`PyUnicode_WriteChar`,
1916+
:c:func:`PyUnicode_CopyCharacters`, :c:func:`PyUnicode_Fill`,
1917+
:c:func:`PyUnicode_WRITE` or similar.
1918+
Since strings are supposed to be immutable, take care to not “use” the
1919+
result while it is being modified. In particular, before it's filled
1920+
with its final contents, a string:
1921+
1922+
- must not be hashed,
1923+
- must not be :c:func:`converted to UTF-8 <PyUnicode_AsUTF8AndSize>`,
1924+
or another non-"canonical" representation,
1925+
- must not have its reference count changed,
1926+
- must not be shared with code that might do one of the above.
1927+
1928+
This list is not exhaustive. Avoiding these uses is your responsibility;
1929+
Python does not always check these requirements.
1930+
1931+
To avoid accidentally exposing a partially-written string object, prefer
1932+
using the :c:type:`PyUnicodeWriter` API, or one of the ``PyUnicode_From*``
1933+
functions below.
1934+
1935+
While :class:`str` objects are usually immutable in Python, this special C API
1936+
returns a :class:`str` object that can be mutated, except if *size* is zero, in which
1937+
case it returns the immutable empty string constant.
1938+
1939+
.. versionadded:: 3.3
1940+
1941+
.. soft-deprecated:: next
1942+
Use the :c:type:`PyUnicodeWriter` API instead.
1943+
1944+
1945+
.. c:function:: void PyUnicode_WRITE(int kind, void *data, \
1946+
Py_ssize_t index, Py_UCS4 value)
1947+
1948+
Write the code point *value* to the given zero-based *index* in a string.
1949+
1950+
The *kind* value and *data* pointer must have been obtained from a
1951+
string using :c:func:`PyUnicode_KIND` and :c:func:`PyUnicode_DATA`
1952+
respectively. You must hold a reference to that string while calling
1953+
:c:func:`!PyUnicode_WRITE`. All requirements of
1954+
:c:func:`PyUnicode_WriteChar` also apply.
1955+
1956+
The function performs no checks for any of its requirements,
1957+
and is intended for usage in loops.
1958+
1959+
While :class:`str` objects are usually immutable in Python, this special C API allows
1960+
mutating a fresh :class:`str` object if the string has not been "used" yet.
1961+
1962+
.. versionadded:: 3.3
1963+
1964+
.. soft-deprecated:: next
1965+
Use the :c:type:`PyUnicodeWriter` API instead.
1966+
1967+
1968+
.. c:function:: Py_ssize_t PyUnicode_CopyCharacters(PyObject *to, \
1969+
Py_ssize_t to_start, \
1970+
PyObject *from, \
1971+
Py_ssize_t from_start, \
1972+
Py_ssize_t how_many)
1973+
1974+
Copy characters from one Unicode object into another. This function performs
1975+
character conversion when necessary and falls back to :c:func:`!memcpy` if
1976+
possible. Returns ``-1`` and sets an exception on error, otherwise returns
1977+
the number of copied characters.
1978+
1979+
While :class:`str` objects are usually immutable in Python, this special C API allows
1980+
mutating a fresh :class:`str` object if the string has not been "used" yet.
1981+
1982+
See :c:func:`PyUnicode_New` for details.
1983+
1984+
.. versionadded:: 3.3
1985+
1986+
.. soft-deprecated:: next
1987+
Use the :c:type:`PyUnicodeWriter` API instead.
1988+
1989+
1990+
.. c:function:: int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length);
1991+
1992+
Resize a Unicode object *\*unicode* to the new *length* in code points.
1993+
1994+
Try to resize the string in place (which is usually faster than allocating
1995+
a new string and copying characters), or create a new string.
1996+
1997+
*\*unicode* is modified to point to the new (resized) object and ``0`` is
1998+
returned on success. Otherwise, ``-1`` is returned and an exception is set,
1999+
and *\*unicode* is left untouched.
2000+
2001+
The function doesn't check string content, the result may not be a
2002+
string in canonical representation.
2003+
2004+
While :class:`str` objects are usually immutable in Python, this special C API
2005+
can resize a :class:`str` object in-place if the string has not been "used" yet.
2006+
It returns a :class:`str` object which can be mutated, except if *size* is zero, in
2007+
which case it returns the immutable empty string constant.
2008+
2009+
.. soft-deprecated:: next
2010+
Use the :c:type:`PyUnicodeWriter` API instead.
2011+
2012+
2013+
.. c:function:: Py_ssize_t PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, \
2014+
Py_ssize_t length, Py_UCS4 fill_char)
2015+
2016+
Fill a string with a character: write *fill_char* into
2017+
``unicode[start:start+length]``.
2018+
2019+
Fail if *fill_char* is bigger than the string maximum character, or if the
2020+
string has more than 1 reference.
2021+
2022+
Return the number of written characters, or return ``-1`` and raise an
2023+
exception on error.
2024+
2025+
While :class:`str` objects are usually immutable in Python, this special C API allows
2026+
mutating a fresh :class:`str` object if the string has not been "used" yet.
2027+
2028+
See :c:func:`PyUnicode_New` for details.
2029+
2030+
.. versionadded:: 3.3
2031+
2032+
.. soft-deprecated:: next
2033+
Use the :c:type:`PyUnicodeWriter` API instead.
2034+
2035+
2036+
.. c:function:: int PyUnicode_WriteChar(PyObject *unicode, Py_ssize_t index, \
2037+
Py_UCS4 character)
2038+
2039+
Write a *character* to the string *unicode* at the zero-based *index*.
2040+
Return ``0`` on success, ``-1`` on error with an exception set.
2041+
2042+
This function checks that *unicode* is a Unicode object, that the index is
2043+
not out of bounds, and that the object's reference count is one.
2044+
See :c:func:`PyUnicode_WRITE` for a version that skips these checks,
2045+
making them your responsibility.
2046+
2047+
While :class:`str` objects are usually immutable in Python, this special C API allows
2048+
mutating a fresh :class:`str` object if the string has not been "used" yet.
2049+
2050+
See :c:func:`PyUnicode_New` for details.
2051+
2052+
.. versionadded:: 3.3
2053+
2054+
.. soft-deprecated:: next
2055+
Use the :c:type:`PyUnicodeWriter` API instead.

0 commit comments

Comments
 (0)