Issue 4618: print_function and unicode_literals don't work together (original) (raw)

Consider:

exarkun@charm:~$ ~/Projects/python/branches/release26-maint/python Python 2.6+ (trunk:66997, Oct 23 2008, 16:02:09) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

def f(o): ... print type(o) ... f('foo') <type 'str'> from future import unicode_literals f('foo') <type 'unicode'> from future import print_function print('foo') foo from io import StringIO print('foo', file=StringIO()) Traceback (most recent call last): File "", line 1, in File "/home/exarkun/Projects/python/branches/release26-maint/Lib/io.py", line 1487, in write s.class.name) TypeError: can't write str to text stream StringIO().write('foo') 3 StringIO().write(b'foo') Traceback (most recent call last): File "", line 1, in File "/home/exarkun/Projects/python/branches/release26-maint/Lib/io.py", line 1487, in write s.class.name) TypeError: can't write str to text stream

It seems the type of a literal string is `str“ when it is an argument to the print function, even with the unicode_literals future import in effect.