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.

classification
Title: unicode(C) invokes C.__unicode__ when __unicode__ is defined
Type: Stage:
Components: Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: livibetter, loewis
Priority: normal Keywords:

Created on 2009-01-25 05:40 by livibetter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg80496 - (view) Author: Yu-Jie Lin (livibetter) Date: 2009-01-25 05:40
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.
msg80497 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-25 06:52
No further bugs will be fixed in Python 2.5, unless they are security
bugs (which this is not). So closing it as "won't fix".
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49300
2009-01-25 06:52:35loewissetstatus: open -> closed
resolution: wont fix
messages: + msg80497
nosy: + loewis
2009-01-25 05:40:38livibettercreate