From f8d8644187d02d3c2464a396872a5bc05a9aa846 Mon Sep 17 00:00:00 2001 From: RUANG Date: Thu, 20 Feb 2025 15:29:58 +0800 Subject: [PATCH 1/7] Add missing PyUnicode_GetDefaultEncoding function documentation --- Doc/c-api/unicode.rst | 5 +++++ Doc/data/refcounts.dat | 3 +++ 2 files changed, 8 insertions(+) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 94110d48ed7d85..7db3868fa4b7b6 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -612,6 +612,11 @@ APIs: decref'ing the returned objects. +.. c:function:: const char* PyUnicode_GetDefaultEncoding(void) + + Return the default encoding format of the string. + + .. 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 d709d2d91b0eb0..e5429050ccd003 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -2750,6 +2750,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: From eedd8b0dbfb648f20dc95d5a7611f370391ec30d Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Thu, 20 Feb 2025 15:53:45 +0800 Subject: [PATCH 2/7] Change desc --- 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 7db3868fa4b7b6..a955b2cd469e54 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -614,7 +614,7 @@ APIs: .. c:function:: const char* PyUnicode_GetDefaultEncoding(void) - Return the default encoding format of the string. + Return a ``"utf-8"`` string constant. .. c:function:: Py_ssize_t PyUnicode_GetLength(PyObject *unicode) From aeeed31809c6217e1397c0446200b79807c61d9f Mon Sep 17 00:00:00 2001 From: RUANG Date: Thu, 20 Feb 2025 22:07:21 +0800 Subject: [PATCH 3/7] More detailed sys.getdefaultencoding() documentation --- Doc/library/sys.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 855237e0984972..0888783259c694 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -771,8 +771,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 str.encode. .. function:: getdlopenflags() From 784947ace1224ce819ad0174ab0104c52113d5af Mon Sep 17 00:00:00 2001 From: RUANG Date: Thu, 20 Feb 2025 22:09:17 +0800 Subject: [PATCH 4/7] Add a tag --- Doc/library/sys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 0888783259c694..335cef0dc149ed 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -772,7 +772,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only .. function:: getdefaultencoding() Return ``'utf-8'``. This is the name of the default string encoding, - used in methods like str.encode. + used in methods like :meth:`str.encode`. .. function:: getdlopenflags() From 5a1c91effdcf9e2fc9b6c5b29d59f8be613978e3 Mon Sep 17 00:00:00 2001 From: RUANG Date: Thu, 20 Feb 2025 22:15:20 +0800 Subject: [PATCH 5/7] Rollback --- Doc/library/sys.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 335cef0dc149ed..855237e0984972 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -771,8 +771,8 @@ always available. Unless explicitly noted otherwise, all variables are read-only .. function:: getdefaultencoding() - Return ``'utf-8'``. This is the name of the default string encoding, - used in methods like :meth:`str.encode`. + Return the name of the current default string encoding used by the Unicode + implementation. .. function:: getdlopenflags() From b10aaa5bb7ec7fa06f19496ea5cac39bbf8ba14a Mon Sep 17 00:00:00 2001 From: RUANG Date: Fri, 21 Feb 2025 10:04:41 +0800 Subject: [PATCH 6/7] Enhance the relevance of the documentation --- Doc/c-api/unicode.rst | 3 ++- Doc/library/sys.rst | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index a955b2cd469e54..57c1c5df4da14f 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -614,7 +614,8 @@ APIs: .. c:function:: const char* PyUnicode_GetDefaultEncoding(void) - Return a ``"utf-8"`` string constant. + Return a ``"utf-8"`` string constant, which corresponds to the + :func:`~sys.getdefaultencoding` function in Python. .. c:function:: Py_ssize_t PyUnicode_GetLength(PyObject *unicode) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 855237e0984972..e61447e4bfc177 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -771,8 +771,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() From 4ff763ced8982bded1df9f55271ed2008d96d861 Mon Sep 17 00:00:00 2001 From: "RUANG (James Roy)" Date: Sat, 22 Feb 2025 10:20:42 +0800 Subject: [PATCH 7/7] Change desc --- Doc/c-api/unicode.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 57c1c5df4da14f..6392aec9de2dd0 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -614,8 +614,11 @@ APIs: .. c:function:: const char* PyUnicode_GetDefaultEncoding(void) - Return a ``"utf-8"`` string constant, which corresponds to the - :func:`~sys.getdefaultencoding` function in Python. + 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)