Skip to content

Commit e38cded

Browse files
[3.12] gh-46236: Add docs for PyUnicode_GetDefaultEncoding() doc (GH-130335) (GH-130512)
* Clarify sys.getdefaultencoding() documentation * Add missing documentation for PyUnicode_GetDefaultEncoding, the C equivalent of sys.getdefaultencoding (cherry picked from commit 9f25c1f) Co-authored-by: RUANG (James Roy) <[email protected]>
1 parent 3c20e8b commit e38cded

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Doc/c-api/unicode.rst

+9
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,15 @@ APIs:
591591
decref'ing the returned objects.
592592
593593
594+
.. c:function:: const char* PyUnicode_GetDefaultEncoding(void)
595+
596+
Return the name of the default string encoding, ``"utf-8"``.
597+
See :func:`sys.getdefaultencoding`.
598+
599+
The returned string does not need to be freed, and is valid
600+
until interpreter shutdown.
601+
602+
594603
.. c:function:: Py_ssize_t PyUnicode_GetLength(PyObject *unicode)
595604
596605
Return the length of the Unicode object, in code points.

Doc/data/refcounts.dat

+3
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,9 @@ PyUnicode_FromFormatV:PyObject*::+1:
27552755
PyUnicode_FromFormatV:const char*:format::
27562756
PyUnicode_FromFormatV:va_list:args::
27572757

2758+
PyUnicode_GetDefaultEncoding:const char*:::
2759+
PyUnicode_GetDefaultEncoding::void::
2760+
27582761
PyUnicode_GetLength:Py_ssize_t:::
27592762
PyUnicode_GetLength:PyObject*:unicode:0:
27602763

Doc/library/sys.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ always available. Unless explicitly noted otherwise, all variables are read-only
751751

752752
.. function:: getdefaultencoding()
753753

754-
Return the name of the current default string encoding used by the Unicode
755-
implementation.
754+
Return ``'utf-8'``. This is the name of the default string encoding, used
755+
in methods like :meth:`str.encode`.
756756

757757

758758
.. function:: getdlopenflags()

0 commit comments

Comments
 (0)