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 livibetter
Recipients livibetter
Date 2009-01-25.05:40:34
SpamBayes Score 2.0046798e-06
Marked as misclassified No
Message-id <1232862040.08.0.372338675263.issue5050@psf.upfronthosting.co.za>
In-reply-to
Content
Run the following code

class A:
  def __str__(self):
    return "__str__"
  def __unicode__(self):
    return "__unicode__"

a = A()

print str(a), unicode(a)
print str(A), unicode(A)

----

Results on Python 2.5.4 (r254:67916):
__str__ __unicode__
__main__.A
Traceback (most recent call last):
  File "/home/livibetter/tmp/unicode_classobj.py", line 14, in <module>
    print str(A), unicode(A)
TypeError: unbound method __unicode__() must be called with A instance
as first argument (got nothing instead)

Results on Python 2.6.1 (r261:67515):
__str__ __unicode__
__main__.A __main__.A

----

I was expecting the same result as on 2.6.1. By my observation,
unicode(C) tries to invoke C.__unicode__ if __unicode__ is defined in C,
where C is a class object.

I believe this behavior is incorrect.
History
Date User Action Args
2009-01-25 05:40:42livibettersetrecipients: + livibetter
2009-01-25 05:40:40livibettersetmessageid: <1232862040.08.0.372338675263.issue5050@psf.upfronthosting.co.za>
2009-01-25 05:40:38livibetterlinkissue5050 messages
2009-01-25 05:40:36livibettercreate