[issue5876] __repr__ returning unicode doesn't work when called implicitly

Serhiy Storchaka report at bugs.python.org
Fri Aug 23 15:31:13 CEST 2013


Serhiy Storchaka added the comment:

In Python 3 ascii() uses the backslashreplace error handler.

>>> class T:
...     def __repr__(self):
...         return '\u20ac\udcff'
... 
>>> print(ascii(T()))
\u20ac\udcff

I think using the backslashreplace error handler in repr() in Python 2.7 is good solution. Here is a patch.

----------
keywords: +patch
nosy: +serhiy.storchaka
stage: test needed -> patch review
Added file: http://bugs.python.org/file31439/unicode_repr.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5876>
_______________________________________


More information about the Python-bugs-list mailing list