Repository navigation
Document PyUnicode_* API #46236
Description
Activity
I was wandering whether the pointer returned by PyUnicode_AsString needs
to be freed after usage (It turned it doesn't since the result is
cached). However, I found out that there isn't any documentation on
docs.python.org about the PyUnicode_AsString and
PyUnicode_AsStringAndSize functions. Although, both are documented in
the public unicodeobject.h header.I notice that the documentation for several other unicode functions is
missing. Quickly, I see:PyUnicode_Resize
PyUnicode_InternImmortal
PyUnicode_GetDefaultEncoding
PyUnicode_SetDefaultEncoding
PyUnicode_BuildEncodingMap
PyUnicode_FromFormatV
PyUnicode_*UTF7*
PyUnicode_AsEncodedObject
PyUnicode_FromOrdinal
PyUnicode_DecodeFSDefault
PyUnicode_DecodeFSDefaultAndSizeIt would probably be a good idea to polish up the documentation for
PyUnicode as much as possible for Python 3000, since extension
developers will certainly need to refer to it a lot during the
transition from 2.x.- addedtype-featureA feature request or enhancementA feature request or enhancement
on Jan 27, 2008 In addition to the above mentioned functions I found these to be
undocumented:PyUnicode_DecodeUTF7
PyUnicode_DecodeUTF7Stateful
PyUnicode_EncodeDecimal
PyUnicode_EncodeUTF7
PyUnicode_FromFormat
PyUnicode_FromString
PyUnicode_FromStringAndSize
PyUnicode_GetMax
PyUnicode_Partition
PyUnicode_RPartition
PyUnicode_RSplitFrom the original list the following functions seem to have been removed:
PyUnicode_InternImmortal
PyUnicode_DecodeFSDefault
PyUnicode_DecodeFSDefaultAndSizeI try to put together a patch for some of these during the weekend.
Ok, here is my shot at a patch for at least some of the undocumented
functions. Namely the following functions are being documented in the patch:PyUnicode_FromFormat
PyUnicode_FromFormatV
PyUnicode_FromString
PyUnicode_FromStringAndSize
PyUnicode_Partition
PyUnicode_RPartition
PyUnicode_RSplitPlease thoroughly review this patch since I didn't really digg into the
source to find out what the functions do but rather just copied old
PyString documentation or derived it from the docs for the Python API.The patch looks alright. I don't like the documentation for
PyUnicode_FromFormatV, however. Here's my attempt to document it:.. cfunction:: PyObject* PyUnicode_FromFormatV(const char *format,
va_list vargs)Equivalent to the function :cfunc:`PyUnicode_FromFormat`, except that
it takes a va_list instead of variable number of arguments.Is it worth applying the patch given the complete rewrite of unicode for 3.3 via PEP-393?
On 30.03.2013 13:09, Mark Lawrence wrote:
Is it worth applying the patch given the complete rewrite of unicode for 3.3 via PEP-393?
PEP-393 only changed the way Unicode is internally stored.
The Unicode API is mostly unaffected by this change.Remaining undocumented functions:
From this issue:
PyUnicode_RSplit
PyUnicode_Partition
PyUnicode_RPartitionFrom bpo-10435:
PyUnicode_IsIdentifier
PyUnicode_Append
PyUnicode_AppendAndDel
PyUnicode_GetDefaultEncoding
PyUnicode_FromOrdinal
PyUnicode_Resize
PyUnicode_GetMax
PyUnicode_InternImmortal
PyUnicode_CHECK_INTERNEDFrom bpo-18688:
Py_UNICODE_REPLACEMENT_CHARACTER
PyUnicodeIter_Type
PyUnicode_AsDecodedObject
PyUnicode_AsDecodedUnicode
PyUnicode_AsEncodedObject
PyUnicode_AsEncodedUnicode
PyUnicode_BuildEncodingMap- changed the title
[-]Documentation for PyUnicode_AsString (et al.) missing.[/-][+]Document PyUnicode_* API[/+]on Apr 30, 2016 38 remaining items
I agree, though they have been deprecated for many years but there is no planned removal date that I can find. Should we just remove them now?
IMO now it's too late for the 3.14 release cycle. It would be better to schedule such removal at the start of a new dev cycle, such as Python 3.15. Someone also has to check if these functions are used in the wild (ex: run a code search).
Reacted by Stan Ulbrychcc @serhiy-storchaka who originally deprecated them in 0093907
A new issue is probably best for this, scheduling for 3.15 seems good for now.
- added a commit that references this issue
on Apr 29, 2025 The list needs to be updated, just
PyUnicode_BuildEncodingMapis left.- added a commit that references this issue
on May 9, 2025 The list is complete. I close the issue. Thanks to everybody who was involved in this old issue (2008!).
Reacted by Stan Ulbrych, Sergey Miryanov and Petr Viktorin
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTodo
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
[edit @encukou]: Converting the lists below to checkboxes:
PyUnicode_InternImmortal(removed in 3.12)PyUnicode_SetDefaultEncoding(removed in 3.2)_PyUnicode_ClearStaticStrings(removed in 3.9)_PyUnicode_EQ(removed in 3.14)_PyUnicode_FromId(private)Linked PRs
PyUnicode_DecodeCodePageStateful#127934PyUnicode_DecodeCodePageStateful(GH-127934) #129961PyUnicode_DecodeCodePageStateful(GH-127934) #129962PyUnicodeIter_Type#132925PyUnicodeIter_Type(GH-132925) #133149