From: Victor Stinner Date: Thu, 9 Apr 2026 11:53:10 +0000 (+0200) Subject: gh-148250: Mention str subclasses in PyUnicodeWriter_WriteStr() doc (#148251) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c524503cd728d609d63d9024a9e2c418ba71f40;p=thirdparty%2FPython%2Fcpython.git gh-148250: Mention str subclasses in PyUnicodeWriter_WriteStr() doc (#148251) --- diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 679823948e73..059a7ef399ae 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1881,6 +1881,10 @@ object. On success, return ``0``. On error, set an exception, leave the writer unchanged, and return ``-1``. + To write a :class:`str` subclass which overrides the :meth:`~object.__str__` + method, :c:func:`PyUnicode_FromObject` can be used to get the original + string. + .. c:function:: int PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj) Call :c:func:`PyObject_Repr` on *obj* and write the output into *writer*.