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 <rep...@bugs.python.org>
<http://bugs.python.org/issue19481>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to