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

2014-07-18 Thread Berker Peksag
Changes by Berker Peksag berker.pek...@gmail.com: -- resolution: fixed - wont fix stage: patch review - resolved ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5876 ___

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

2013-08-24 Thread Armin Rigo
Armin Rigo added the comment: @Serhiy: it's a behavior change and as such not an option for a micro release. For example, the following legal code would behave differently: it would compute s = '\\u1234' instead of s = 'UTF8:\xe1\x88\xb4'. try: s = repr(x) except

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

2013-08-23 Thread Serhiy Storchaka
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

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

2013-08-23 Thread STINNER Victor
STINNER Victor added the comment: This change is going to break backward compatibility. I don't think that it can be done in Python 2.7.x, and there is no Python 2.8 (PEP 404). -- ___ Python tracker rep...@bugs.python.org

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

2013-08-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: How it can break backward compatibility? Currently repr() just raises UnicodeEncodeError. UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 0: ordinal not in range(128) With patch it always returns 8-bit string. As far as

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

2013-08-23 Thread STINNER Victor
STINNER Victor added the comment: How it can break backward compatibility? Currently repr() just raises UnicodeEncodeError. It depends on sys.getdefaultencoding() which can be modified in the site module (or in a PYTHONSTARTUP script) using sys.setdefaultencoding(). It should not possible

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

2013-08-23 Thread Armin Rigo
Armin Rigo added the comment: @Serhiy: it would certainly break a program that tries to call the repr() and catches the UnicodeEncodeError to do something else, like encode the data differently. -- ___ Python tracker rep...@bugs.python.org

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

2013-08-23 Thread Marc-Andre Lemburg
Marc-Andre Lemburg added the comment: .__repr__() is not really allowed to return Unicode objects in Python 2.x. If you do this, you're on your own. The CPython internals try to convert any non-str object to a str object, but this is only done to assure that PyObject_Repr() always returns a

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

2013-08-23 Thread STINNER Victor
STINNER Victor added the comment: I'd suggest closing this as won't fix. Agreed, it's time to upgrade to Python 3! -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5876

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

2013-08-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It depends on sys.getdefaultencoding() which can be modified in the site module (or in a PYTHONSTARTUP script) using sys.setdefaultencoding(). Of course. Every successful without patch repr() will left same with patch. However the patch allows you to see

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

2013-08-23 Thread Marc-Andre Lemburg
Marc-Andre Lemburg added the comment: Serhiy Storchaka wrote: .__repr__() is not really allowed to return Unicode objects in Python 2.x. If you do this, you're on your own. PyObject_Repr() contains a code which converts unicode to str and raise an exception if __repr__() result is not

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

2011-09-06 Thread Armin Rigo
Armin Rigo ar...@users.sourceforge.net added the comment: A __repr__() that returns unicode can, in CPython 2.7 be used in %s % x or in u%s % x --- both expressions then return a unicode without doing any encoding --- but it cannot be used anywhere else, e.g. in %r % x or in repr(x).

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

2011-09-05 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: I think it’s not an implicit vs. explicit call problem, rather repr vs. str. IIRC, in 2.x it is allowed that __str__ returns a unicode object, and str will convert it to a str. To do that, it will use the default encoding, which is ASCII in

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

2011-09-05 Thread STINNER Victor
STINNER Victor victor.stin...@haypocalc.com added the comment: I think that this issue is a duplicate of #4947 which has been fixed in Python 2.7.1. Can you retry with Python 2.7.2 (or 2.7.1)? -- nosy: +haypo ___ Python tracker

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

2011-09-05 Thread Tomasz Melcer
Tomasz Melcer li...@o2.pl added the comment: Debian SID. No, it wasn't. Python 2.7.2+ (default, Aug 16 2011, 09:23:59) [GCC 4.6.1] on linux2 Type help, copyright, credits or license for more information. class T(object): ... def __repr__(self): return u'あみご' ... T().__repr__()

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

2011-09-05 Thread STINNER Victor
STINNER Victor victor.stin...@haypocalc.com added the comment: 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

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

2011-09-03 Thread Nam Nguyen
Changes by Nam Nguyen bits...@gmail.com: -- nosy: +Nam.Nguyen ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5876 ___ ___ Python-bugs-list mailing

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

2009-04-29 Thread Tomasz Melcer
New submission from Tomasz Melcer li...@o2.pl: Invitation... (Debian Sid, gnome-terminal with pl_PL.UTF8 locales) Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. Lets create some class... class T(object):

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

2009-04-29 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5876 ___ ___ Python-bugs-list

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

2009-04-29 Thread R. David Murray
R. David Murray rdmur...@bitdance.com added the comment: This worked in 2.4 and stopped working in 2.5. It's not a problem in 3.x. (2.5 is in security-fix-only mode, so I'm removing it from versions). -- components: +Interpreter Core -Extension Modules nosy: +r.david.murray priority: