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 vstinner
Recipients Nam.Nguyen, eric.araujo, ezio.melotti, lemburg, liori, r.david.murray, vstinner
Date 2011-09-05.20:07:14
SpamBayes Score 8.71629e-09
Marked as misclassified No
Message-id <201109052206.55336.victor.stinner@haypocalc.com>
In-reply-to <1315243662.59.0.256574529098.issue5876@psf.upfronthosting.co.za>
Content
> Debian SID. No, it wasn't.

Oh ok, gotcha: repr() always returns a str string. If obj.__repr__() returns a 
Unicode string, the string is encoded to the default encoding. By default, the 
default encoding is ASCII.

$ ./python -S 
Python 2.7.2+ (2.7:85a12278de69, Sep  2 2011, 00:21:57) 
[GCC 4.6.0 20110603 (Red Hat 4.6.0-10)] on linux2
>>> import sys
>>> sys.setdefaultencoding('ISO-8859-1')
>>> class A(object):
...  def __repr__(self): return u'\xe9'
... 
>>> repr(A())
'\xe9'

Don't do that at home! Change the default encoding is not a good idea.

I don't think that repr(obj) can be changed to return Unicode if 
obj.__repr__() returns Unicode. It is too late to change such thing in Python 
2.
History
Date User Action Args
2011-09-05 20:07:15vstinnersetrecipients: + vstinner, lemburg, ezio.melotti, eric.araujo, r.david.murray, liori, Nam.Nguyen
2011-09-05 20:07:15vstinnerlinkissue5876 messages
2011-09-05 20:07:14vstinnercreate