Issue1510227

classification
Title: difference between repr() and __repr__()
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pjenvey Nosy List: cgroves, leouserz, m_small, pjenvey
Priority: normal Keywords:

Created on 2006-06-21.21:32:07 by m_small, last changed 2008-04-15.01:03:10 by pjenvey.

Messages
msg1172 (view) Author: Matt Small (m_small) Date: 2006-06-21.21:32:07
I'm seeing weird differences between repr() and
__repr__() that don't seem to appear in regular Python.

For example:

>>> foo='foo\b\n'
>>> repr(foo)
"'foo\\b\\n'"
>>> foo.__repr__()
'foo\b\n'

This is especially bad from Java, as the __repr__() is
all you have access to.  To reproduce from Java, I put
code in _codecs.java, in a new escape_encode function;
I'll submit this as part of my first pickle patch.
msg1173 (view) Author: Charlie Groves (cgroves) Date: 2006-11-20.01:58:55
Matt, I thought you'd applied your patch, but this still seems to be broken in trunk and on the 2.3 branch.  Did this not end up in the patch?
msg1174 (view) Author: Deleted User leouserz (leouserz) Date: 2006-12-21.23:43:30
Im going to take a wild guess here that the problem is because
repr(foo)

will go to __builtin__ repr that calls:


public PyString __repr__() {

    return new PyString(encode_UnicodeEscape(string, true));

}

while
foo.__repr__

calls
    final String str_toString() {

        return string;

    }

Incidentally, python returns:
"'foo\\x08\\n'"
for both repr and __repr__

leouser
msg3152 (view) Author: Philip Jenvey (pjenvey) Date: 2008-04-15.01:02:08
this is fixed on trunk as of r4346
History
Date User Action Args
2008-04-15 01:03:10pjenveysetcomponents: + Core, - None
2008-04-15 01:02:09pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg3152
2008-04-14 07:30:28pjenveysetassignee: pjenvey
nosy: + pjenvey
2006-06-21 21:32:07m_smallcreate