[Python-Dev] cpython: Document PyUnicode_Copy() and PyUnicode_EncodeCodePage()

Antoine Pitrou solipsis at pitrou.net
Sun Dec 11 23:46:09 CET 2011


Le dimanche 11 décembre 2011 à 23:44 +0100, "Martin v. Löwis" a écrit :
> Am 09.12.2011 20:32, schrieb Antoine Pitrou:
> > On Fri, 09 Dec 2011 19:51:14 +0100
> > Victor Stinner <victor.stinner at haypocalc.com> wrote:
> >> 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()).
> > 
> > Then the doc should mention that the returned string can be modified.
> > Otherwise it's a bit obscure why the function exists.
> 
> I'm skeptical about this modification part. If you make a copy, it's
> not clear at all that the new characters that you put in will fit
> in range with the width of the unicode string. Even decreasing the
> ordinal of a character may be incorrect as the result may not be
> canonical anymore.

Ah, good point. And perhaps a good reason to make the API private.

Regards

Antoine.




More information about the Python-Dev mailing list