[Patches] [ python-Patches-470578 ] Fixes to synchronize unicode() and str()
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 19 Oct 2001 05:07:34 -0700
Patches item #470578, was opened at 2001-10-12 07:03
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=470578&group_id=5470
Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: M.-A. Lemburg (lemburg)
>Assigned to: Barry Warsaw (bwarsaw)
Summary: Fixes to synchronize unicode() and str()
Initial Comment:
This patch implements what we have discussed on python-dev late in September: str(obj) and
unicode(obj) should behave similar, while the old behaviour is retained for unicode(obj, encoding, errors).
The patch also adds a new feature with which objects can provide unicode(obj) with input data: the
__unicode__ method. Currently no new tp_unicode slot is implemented; this is left as option for the
future.
Note that PyUnicode_FromEncodedObject() no longer accepts Unicode objects as input. The API name
already suggests that Unicode objects do not belong in the list of acceptable objects and the functionality
was only needed because PyUnicode_FromEncodedObject() was being used directly by unicode(). The
latter was changed in the discussed way:
* unicode(obj) calls PyObject_Unicode()
* unicode(obj, encoding, errors) calls PyUnicode_FromEncodedObject()
One thing left open to discussion is whether to leave the PyUnicode_FromObject() API as a thin API
extension on top of PyUnicode_FromEncodedObject() or to turn it into a (macro) alias for
PyObject_Unicode() and deprecate it. Doing so would have some surprising consequences though, e.g.
u"abc" + 123 would turn out as u"abc123"...
Please check and then reassign to me for the checkin.
----------------------------------------------------------------------
>Comment By: M.-A. Lemburg (lemburg)
Date: 2001-10-19 05:07
Message:
Logged In: YES
user_id=38388
Added patch which includes the docs and additional tests.
Barry, please check this patch into the b1 tree and close
the patch. Thanks !
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-10-18 19:05
Message:
Logged In: YES
user_id=6380
I'm going to check this in, because MAL said he didn't have
time before the deadline.
MAL, if you have an improvement that cannot wait until after
beta 1, check in on the trunk and mail Barry a context diff.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-10-12 13:36
Message:
Logged In: YES
user_id=6380
u"abc" + 123 should definitely raise an exception!
Please provide a test suite that shows off the new behavior
and the differences between old and new behavior.
Please provide documentation patches.
Without these, I can't really tell whether the patched code
works as desired.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=470578&group_id=5470