-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-46236: Add missing PyUnicode_GetDefaultEncoding() doc #130335
base: main
Are you sure you want to change the base?
Conversation
cc @vstinner |
As usual, the documentation does not require a NEWS (I hope I remember correctly). I'm aware that this function returns a |
I'd link to Perhaps this should be soft-deprecated. |
Alright, something interesting happened.
Should I modify its description? e.g.,
In other words, should I add
Even so, do I still need to add this tag? |
Hm, looking further, looks like the “current default string encoding used by the Unicode implementation” is what (click for Python 2 behaviour)>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>> u'á'.encode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 0: ordinal not in range(128)
>>> import ctypes
>>> ctypes.pythonapi.PyUnicodeUCS4_SetDefaultEncoding("utf-8") # hack!
0
>>> sys.getdefaultencoding()
'utf-8'
>>> 'á'.encode()
'\xc3\xa1' It might be good to clarify this in the
(So, UTF-8 is not a CPython implementation detail.) |
That's needed to get a Python object, as opposed to a |
I'd prefer including the |
Doc/c-api/unicode.rst
Outdated
Return a ``"utf-8"`` string constant, which corresponds to the | ||
:func:`~sys.getdefaultencoding` function in Python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest this wording, plus making lifetime explicit since we're returning a buffer.
(Currently the string is static of course, but if it'd ever become dynamic again, it'd need to be borrowed from the interpreter.)
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. |
📚 Documentation preview 📚: https://cpython-previews--130335.org.readthedocs.build/