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 ncoghlan
Recipients barry, cvrebert, exarkun, ezio.melotti, ncoghlan, pitrou
Date 2009-12-13.04:24:36
SpamBayes Score 6.6147088e-12
Marked as misclassified No
Message-id <1260678278.88.0.678718023561.issue6108@psf.upfronthosting.co.za>
In-reply-to
Content
As Antoine said, there's a reason BaseException now implements both
__str__ and __unicode__ and doesn't implement the latter in terms of the
former - it's the only way to consistently support Unicode arguments
that can't be encoded to an 8-bit ASCII string:

>>> str(Exception(u"\xc3\xa0"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position
0-1: ordinal not in range(128)
>>> unicode(Exception(u"\xc3\xa0"))
u'\xc3\xa0'

For some of the exception subclasses that will always return ASCII (e.g.
KeyError, which calls repr() on its arguments) then defining __unicode__
in terms of __str__ as Ezio suggests will work.

For others (as happened with BaseException itself), the __unicode__
method will need to be a reimplementation that avoids trying to encode
potentially non-ASCII characters into an 8-bit ASCII string.
History
Date User Action Args
2009-12-13 04:24:38ncoghlansetrecipients: + ncoghlan, barry, exarkun, pitrou, ezio.melotti, cvrebert
2009-12-13 04:24:38ncoghlansetmessageid: <1260678278.88.0.678718023561.issue6108@psf.upfronthosting.co.za>
2009-12-13 04:24:37ncoghlanlinkissue6108 messages
2009-12-13 04:24:36ncoghlancreate