From c5dd8284e37ac10f7cb17fc3ab40313f76895dda Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Mon, 24 Feb 2025 22:37:21 +0800 Subject: [PATCH] gh-46236: Add docs for PyUnicode_GetDefaultEncoding() doc (GH-130335) * Clarify sys.getdefaultencoding() documentation * Add missing documentation for PyUnicode_GetDefaultEncoding, the C equivalent of sys.getdefaultencoding (cherry picked from commit 9f25c1f012c8d432a93bf2dcad5f19a64dc00d3c) Co-authored-by: RUANG (James Roy) --- Doc/c-api/unicode.rst | 9 +++++++++ Doc/data/refcounts.dat | 3 +++ Doc/library/sys.rst | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 3dd3b3a36c2ff5..cce15b700a845c 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -591,6 +591,15 @@ APIs: decref'ing the returned objects. +.. c:function:: const char* PyUnicode_GetDefaultEncoding(void) + + Return the name of the default string encoding, ``"utf-8"``. + See :func:`sys.getdefaultencoding`. + + The returned string does not need to be freed, and is valid + until interpreter shutdown. + + .. c:function:: Py_ssize_t PyUnicode_GetLength(PyObject *unicode) Return the length of the Unicode object, in code points. diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index fb1215df777644..cb186b6db3398b 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2755,6 +2755,9 @@ PyUnicode_FromFormatV:PyObject*::+1: PyUnicode_FromFormatV:const char*:format:: PyUnicode_FromFormatV:va_list:args:: +PyUnicode_GetDefaultEncoding:const char*::: +PyUnicode_GetDefaultEncoding::void:: + PyUnicode_GetLength:Py_ssize_t::: PyUnicode_GetLength:PyObject*:unicode:0: diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 2ba70cbf7c6a44..add1d53153c39d 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -751,8 +751,8 @@ always available. Unless explicitly noted otherwise, all variables are read-only .. function:: getdefaultencoding() - Return the name of the current default string encoding used by the Unicode - implementation. + Return ``'utf-8'``. This is the name of the default string encoding, used + in methods like :meth:`str.encode`. .. function:: getdlopenflags()