From 823cf8fff8107188ea12cd0eda18043413c34227 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Apr 2026 15:15:08 +0200 Subject: [PATCH 1/2] gh-148250: Mention str subclasses in PyUnicodeWriter_WriteStr() doc --- Doc/c-api/unicode.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 679823948e73b5..8a84d5b64010ca 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, :class:`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*. From 91c5a0441a0c3f4a9d1ddcbc115ef7f0fe8db3b7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 8 Apr 2026 16:15:24 +0200 Subject: [PATCH 2/2] Fix Sphinx formatting --- Doc/c-api/unicode.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 8a84d5b64010ca..059a7ef399ae0f 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1882,7 +1882,7 @@ object. 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, :class:`PyUnicode_FromObject` can be used to get the original + method, :c:func:`PyUnicode_FromObject` can be used to get the original string. .. c:function:: int PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)