Issue 4225: unicode_literals doesn't work in exec (original) (raw)

Created on 2008-10-28 22:06 by benjamin.peterson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_exec_literals.patch benjamin.peterson,2008-10-28 22:10
pass_flags.patch benjamin.peterson,2008-10-29 20:56
parser_module_fixed_too.patch benjamin.peterson,2008-10-30 22:31
Pull Requests
URL Status Linked Edit
PR 23143 open python-dev,2020-11-04 11:39
Messages (8)
msg75307 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-28 22:06
exec "from __future__ import unicode_literals; print type('')" gives <type 'str'> in 2.6/2.7. It's the result of flags not being passed from the parser to AST.
msg75312 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-29 08:57
The attached patch works, but can be simplified by using a stack variable: Index: pythonrun.c =================================================================== --- pythonrun.c (revision 66902) +++ pythonrun.c (working copy) @@ -1284,7 +1290,13 @@ { PyObject *ret = NULL; mod_ty mod; - PyArena *arena = PyArena_New(); + PyCompilerFlags localflags; + PyArena *arena; + + if (flags == NULL) + flags = &localflags; + + arena = PyArena_New(); if (arena == NULL) return NULL;
msg75332 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-29 20:56
This patch uses heap variables and tries to catch more places.
msg75333 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-29 22:43
The newer patch is good. I found another use of PyAST_FromNode() with NULL flags, and which has the same problem: import parser s=parser.suite( "from __future__ import unicode_literals; print type('')") eval(s.compile()) But I don't know how to correct this: the CO_FUTURE_UNICODE_LITERALS flag is determined during the parse phase (in parser.suite), but this value is lost and not passed to s.compile(). Maybe PyST_Object could grow a "st_flags" attribute.
msg75389 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-30 22:28
Here's a patch that handles the parser module.
msg75399 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-31 00:45
The patch is good, except that you removed "static" before the function err_input (?)
msg75406 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-31 02:16
The removal of the "static" was a mistake. Fixed in r67066.
msg75429 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-31 20:48
This problem will still persist for anybody who uses PyParser_* APIs and then PyNode_Compile, but we can probably only document that.
History
Date User Action Args
2022-04-11 14:56:40 admin set github: 48475
2020-11-04 11:39:21 python-dev set nosy: + python-devpull_requests: + <pull%5Frequest22055>
2008-10-31 20:48:02 benjamin.peterson set messages: +
2008-10-31 02:16:41 benjamin.peterson set status: open -> closedresolution: fixedmessages: +
2008-10-31 00:45:44 amaury.forgeotdarc set messages: +
2008-10-30 22:31:32 benjamin.peterson set files: + parser_module_fixed_too.patch
2008-10-30 22:31:23 benjamin.peterson set files: - parser_module_fixed_too.patch
2008-10-30 22:28:20 benjamin.peterson set files: + parser_module_fixed_too.patchmessages: +
2008-10-29 22:43:41 amaury.forgeotdarc set messages: +
2008-10-29 20:56:28 benjamin.peterson set files: + pass_flags.patchmessages: +
2008-10-29 08:57:30 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2008-10-28 22:10:07 benjamin.peterson set files: + fix_exec_literals.patch
2008-10-28 22:09:55 benjamin.peterson set files: - fix_exec_literals.patch
2008-10-28 22:06:43 benjamin.peterson create