[Python-Dev] cpython: Document PyUnicode_Copy() and PyUnicode_EncodeCodePage()
Victor Stinner
victor.stinner at haypocalc.com
Fri Dec 9 19:51:14 CET 2011
On 09/12/2011 01:35, Antoine Pitrou wrote:
> On Fri, 09 Dec 2011 00:16:02 +0100
> victor.stinner<python-checkins at python.org> wrote:
>>
>> +.. c:function:: PyObject* PyUnicode_Copy(PyObject *unicode)
>> +
>> + Get a new copy of a Unicode object.
>> +
>> + .. versionadded:: 3.3
>
> I'm not sure I understand. Why would you make a copy of an immutable
> object?
PyUnicode_Copy() can be used to modify a string to create a new string
with the same length. It is used for example by str.upper(),
str.title(), ... (fixup()).
It is also used by str.__getnewargs__(). I am not sure that
str.__getnewargs__() must be a copy of str (s.__getnewargs__() is not x).
As mentionned by Martin, PyUnicode_Copy() is also used to get "an exact"
Unicode object when you have a subtype.
We can maybe make the function private.
Victor
More information about the Python-Dev
mailing list