[Patches] [ python-Patches-1159501 ] Improve %s support for unicode
SourceForge.net
noreply at sourceforge.net
Wed Apr 20 23:27:09 CEST 2005
Patches item #1159501, was opened at 2005-03-09 02:43
Message generated for change (Comment added) made by lemburg
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1159501&group_id=5470
Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Neil Schemenauer (nascheme)
Assigned to: Fredrik Lundh (effbot)
Summary: Improve %s support for unicode
Initial Comment:
"'%s' % unicode_string" produces a unicode result. I
think the following code should also return a unicode
string:
class Wrapper:
....def __str__(self):
........return unicode_string
'%s' % Wrapper()
That behavior would make it easier to write library
code that can work with either str objects or unicode
objects.
The fix is pretty simple (see that attached patch).
Perhaps the PyObject_Text function should be called
_PyObject_Text instead. Alternatively, if the function
is make public then we should document it and perhaps
also provide a builtin function called 'text' that uses it.
----------------------------------------------------------------------
>Comment By: M.-A. Lemburg (lemburg)
Date: 2005-04-20 23:27
Message:
Logged In: YES
user_id=38388
Looks OK to me; not sure what you mean with __text__ -
__str__ already has taken that role long ago.
----------------------------------------------------------------------
Comment By: Neil Schemenauer (nascheme)
Date: 2005-04-20 23:00
Message:
Logged In: YES
user_id=35752
Assigning to effbot for review. He had mentioned something
about __text__ at one point.
----------------------------------------------------------------------
Comment By: Neil Schemenauer (nascheme)
Date: 2005-03-10 22:13
Message:
Logged In: YES
user_id=35752
attempt to attach patch again
----------------------------------------------------------------------
Comment By: Neil Schemenauer (nascheme)
Date: 2005-03-10 22:12
Message:
Logged In: YES
user_id=35752
Attaching a better patch. Add a builtin function called
"text". Change PyObject_Text to check the return types as
suggested by Mark. Update the documentation and the tests.
----------------------------------------------------------------------
Comment By: M.-A. Lemburg (lemburg)
Date: 2005-03-09 11:10
Message:
Logged In: YES
user_id=38388
Nice patch.
Only nit: PyObject_Text() should check that the result of
tp_str() is indeed either a string or unicode instance
(possibly from a subclass). Otherwise, the function wouldn't
be able to guarantee this feature - which is what it's all
about.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1159501&group_id=5470
More information about the Patches
mailing list