[New-bugs-announce] [issue11900] 2.7.1 unicode subclasses not calling __str__() for print statement
Dave Opstad
report at bugs.python.org
Thu Apr 21 20:14:28 CEST 2011
New submission from Dave Opstad <dave.opstad at monotypeimaging.com>:
Python 2.7.1 doesn't appear to do the usual implicit call to str() for subclasses of unicode. In the following snippet, I would have expected print myTest and print str(myTest) to behave the same:
>>> class Test(unicode):
... def __str__(self):
... print "In __str__"
... return (u"*** " + self + u" ***").encode('utf-8')
... def __unicode__(self):
... print "In __unicode__"
... return u"*** " + self + u" ***"
...
>>> myTest = Test(u"abc")
>>> print myTest
abc
>>> print str(myTest)
In __str__
*** abc ***
>>> print unicode(myTest)
In __unicode__
*** abc ***
----------
components: Unicode
messages: 134231
nosy: opstad
priority: normal
severity: normal
status: open
title: 2.7.1 unicode subclasses not calling __str__() for print statement
type: behavior
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11900>
_______________________________________
More information about the New-bugs-announce
mailing list