[Python-Dev] Inconsistency in 2.4.3 for __repr__() returning unicode
Hye-Shik Chang
hyeshik at gmail.com
Mon Mar 27 09:40:30 CEST 2006
We got an inconsistency for __repr__() returning unicode as
reported in http://python.org/sf/1459029 :
class s1:
def __repr__(self):
return '\\n'
class s2:
def __repr__(self):
return u'\\n'
print repr(s1()), repr(s2())
Until 2.4.2: \n \n
2.4.3: \n \\n
\\n looks bit weird but it's correct. As once discussed[1] in
python-dev before, if __repr__ returns unicode object,
PyObject_Repr encodes it via unicode-escape codec. So,
non-latin character also could be in repr neutrally.
But our unicode-escape had a bug since when it is introduced.
The bug was that it doesn't escape backslashes. Therefore,
backslashes wasn't escaped in repr while it sholud be escaped
because we used the unicode-escape codec.
So, fixing the bug made a behavior inconsistency.
How do we resolve the problem?
Hye-Shik
[1] http://mail.python.org/pipermail/python-dev/2000-July/005353.html
More information about the Python-Dev
mailing list