This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unicode_literals doesn't work in exec
Type: Stage:
Components: Interpreter Core Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, georg.brandl, python-dev
Priority: high Keywords: needs review, patch

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:40adminsetgithub: 48475
2020-11-04 11:39:21python-devsetnosy: + python-dev

pull_requests: + pull_request22055
2008-10-31 20:48:02benjamin.petersonsetmessages: + msg75429
2008-10-31 02:16:41benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg75406
2008-10-31 00:45:44amaury.forgeotdarcsetmessages: + msg75399
2008-10-30 22:31:32benjamin.petersonsetfiles: + parser_module_fixed_too.patch
2008-10-30 22:31:23benjamin.petersonsetfiles: - parser_module_fixed_too.patch
2008-10-30 22:28:20benjamin.petersonsetfiles: + parser_module_fixed_too.patch
messages: + msg75389
2008-10-29 22:43:41amaury.forgeotdarcsetmessages: + msg75333
2008-10-29 20:56:28benjamin.petersonsetfiles: + pass_flags.patch
messages: + msg75332
2008-10-29 08:57:30amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg75312
2008-10-28 22:10:07benjamin.petersonsetfiles: + fix_exec_literals.patch
2008-10-28 22:09:55benjamin.petersonsetfiles: - fix_exec_literals.patch
2008-10-28 22:06:43benjamin.petersoncreate