Skip to content

Commit 9f25c1f

Browse files
authored
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
1 parent fc8d2cb commit 9f25c1f

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
@@ -607,6 +607,15 @@ APIs:
607607
decref'ing the returned objects.
608608
609609
610+
.. c:function:: const char* PyUnicode_GetDefaultEncoding(void)
611+
612+
Return the name of the default string encoding, ``"utf-8"``.
613+
See :func:`sys.getdefaultencoding`.
614+
615+
The returned string does not need to be freed, and is valid
616+
until interpreter shutdown.
617+
618+
610619
.. c:function:: Py_ssize_t PyUnicode_GetLength(PyObject *unicode)
611620
612621
Return the length of the Unicode object, in code points.

Doc/data/refcounts.dat

+3
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,9 @@ PyUnicode_FromFormatV:PyObject*::+1:
27702770
PyUnicode_FromFormatV:const char*:format::
27712771
PyUnicode_FromFormatV:va_list:args::
27722772

2773+
PyUnicode_GetDefaultEncoding:const char*:::
2774+
PyUnicode_GetDefaultEncoding::void::
2775+
27732776
PyUnicode_GetLength:Py_ssize_t:::
27742777
PyUnicode_GetLength:PyObject*:unicode:0:
27752778

Doc/library/sys.rst

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

772772
.. function:: getdefaultencoding()
773773

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

777777

778778
.. function:: getdlopenflags()

0 commit comments

Comments
 (0)