This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author doerwalter
Recipients
Date 2001-09-09.15:41:14
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
The unicode constructor returns the object passed in, 
when an instance of a subclass of unicode is passed in:
--
class U(unicode):
   pass

u1 = U(u"foo")
print type(u1)
u2 = unicode(u1)
print type(u2) 
--
this gives
--
<type '__main__.U'>
<type '__main__.U'>
--
instead of
--
<type '__main__.U'>
<type 'unicode'>
--
as it probably should be (The unicode constructor 
should construct unicode objects). With the current 
behaviour it is nearly impossible to construct a 
unicode object with the value of an instance of a 
unicode subclass, because most methods are optimized 
to return the original object if possible, e.g.
--
print type(unicode.__getslice__(u1, 0, 3))
print type(unicode.__getslice__(u1, 0, 2))
--
gives
--
<type '__main__.U'>
<type 'unicode'>
--
This should be made consistent, so that either a 
unicode object is always returned, or all methods use 
a "virtual constructor", i.e. create an object of the 
type passed in. This would simplify deriving classes 
from unicode as far fewer methods have to be 
overwritten.

But first of all the constructor should be fixed, so 
that the argument is returned unmodified only when it 
is an instance of unicode and not of a unicode 
subclass.
History
Date User Action Args
2007-08-23 13:56:18adminlinkissue460020 messages
2007-08-23 13:56:18admincreate