Message7581

Author irmen
Recipients irmen
Date 2013-01-19.15:09:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1358608177.34.0.246873717165.issue2008@psf.upfronthosting.co.za>
In-reply-to
Content
The compile() function doesn't pay attention to the unicode_literals flag. It still parses str literals as str, instead of unicode.


[G:\temp]type tests.py
import __future__
import ast

# code object
c = compile("s='hello'; print s,type(s)",
            "<unknown>", mode="exec",
            flags=__future__.unicode_literals.compiler_flag)
exec c

# ast
a = compile("'hello'",
            "<unknown>", mode="eval",
            flags=ast.PyCF_ONLY_AST | __future__.unicode_literals.compiler_flag)
print a.body.s, type(a.body.s)

[G:\temp]python tests.py
hello <type 'unicode'>
hello <type 'unicode'>

[G:\temp]d:\TOOLS\jython-repo\dist\bin\jython.bat tests.py
hello <type 'str'>
hello <type 'str'>


The last 2 should be 'unicode' as well. Doing from __future__ import unicode_literals, which works for normal python modules, doesn't help for the compile() function.
History
Date User Action Args
2013-01-19 15:09:37irmensetrecipients: + irmen
2013-01-19 15:09:37irmensetmessageid: <1358608177.34.0.246873717165.issue2008@psf.upfronthosting.co.za>
2013-01-19 15:09:37irmenlinkissue2008 messages
2013-01-19 15:09:37irmencreate