[issue19481] IDLE hangs while printing instance of Unicode subclass

Serhiy Storchaka report at bugs.python.org
Mon Nov 4 09:40:45 CET 2013


Serhiy Storchaka added the comment:

I suppose this is related to pickling.

I were puzzled why it works with bytearray subclasses. But now I investigated that print() implicitly converts str and bytearray subclasses to str and left unicode subclasses as is. You can reproduce this bug for str and bytearray subclasses if use sys.stdout.write() instead of print().

Here is a patch for 2.7 which fixes the issue for str and bytearray subclasses too. 3.x needs patch too.

>>> class U(unicode): pass

>>> class S(str): pass

>>> class BA(bytearray): pass

>>> import sys
>>> sys.stdout.write(u'\u20ac')
€
>>> sys.stdout.write('\xe2\x82\xac')
€
>>> sys.stdout.write(bytearray('\xe2\x82\xac'))
€
>>> sys.stdout.write(U(u'\u20ac'))
€
>>> sys.stdout.write(S('\xe2\x82\xac'))
€
>>> sys.stdout.write(BA('\xe2\x82\xac'))
€

----------
versions: +Python 3.3, Python 3.4
Added file: http://bugs.python.org/file32490/idle_write_string_subclass-2.7.patch

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


More information about the Python-bugs-list mailing list