[pypy-issue] [issue857] u"%s" % O() that has unicode __repr__() fails
tracker at bugs.pypy.org
Sat Sep 3 12:07:14 CEST 2011
Armin Rigo <armin.rigo at gmail.com> added the comment:
With a __repr__ that returns an unencodable unicode string, you will get an
encoding error on CPython if you try to do anything at all, like str(O()) or
repr(O()) or print O() or `O()`. Even doing '%r' % O(). It seems that '%s' %
O() is the only thing that you can do.
Indeed, I can't believe it, but looking at the source code of CPython, there is
a special function _PyObject_Str() that is called *only* from '%s' formatting.
All other places call PyObject_Str() or PyObject_Repr(), which will encode the
unicode string. It makes no sense to me... What should we do? Copy this
horribly strange special case???
PyPy bug tracker <tracker at bugs.pypy.org>
More information about the pypy-issue