[issue19481] IDLE hangs while printing instance of Unicode subclass

Terry J. Reedy report at bugs.python.org
Mon Dec 9 22:10:40 CET 2013


Terry J. Reedy added the comment:

> [2.7] print() implicitly converts str and bytearray subclasses to str and left unicode subclasses as is.

This strikes me as possibly a bug in print, but even if that were changed, there is still the issue of sys.stdout.write and pickle. While the patch is a great improvement, it changes the behavior of sys.stdout.write(s), which acts like it calls str.__str__(s) rather than str(s) == s.__str__

---
class S(str):
    def __str__(self):
        return 'S: ' + str.__str__(self)

s = S('foo')
print(s, str(s), str.__str__(s))

import sys
sys.stdout.write(s)
---
S: foo S: foo foo
foo

on the console (hang after first line on Idle)

I am testing the patch with str(s) changed to str.__str__(s).

----------

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


More information about the Python-bugs-list mailing list