Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicode_literals doesn't work in exec #48475

Closed
benjaminp opened this issue Oct 28, 2008 · 8 comments
Closed

unicode_literals doesn't work in exec #48475

benjaminp opened this issue Oct 28, 2008 · 8 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@benjaminp
Copy link
Contributor

BPO 4225
Nosy @birkenfeld, @amauryfa, @benjaminp
PRs
  • bpo-42258: argparse: show choices once per argument #23143
  • Files
  • fix_exec_literals.patch
  • pass_flags.patch
  • parser_module_fixed_too.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2008-10-31.02:16:41.120>
    created_at = <Date 2008-10-28.22:06:43.407>
    labels = ['interpreter-core']
    title = "unicode_literals doesn't work in exec"
    updated_at = <Date 2020-11-04.11:39:21.453>
    user = 'https://github.com/benjaminp'

    bugs.python.org fields:

    activity = <Date 2020-11-04.11:39:21.453>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-10-31.02:16:41.120>
    closer = 'benjamin.peterson'
    components = ['Interpreter Core']
    creation = <Date 2008-10-28.22:06:43.407>
    creator = 'benjamin.peterson'
    dependencies = []
    files = ['11903', '11906', '11912']
    hgrepos = []
    issue_num = 4225
    keywords = ['patch', 'needs review']
    message_count = 8.0
    messages = ['75307', '75312', '75332', '75333', '75389', '75399', '75406', '75429']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'amaury.forgeotdarc', 'benjamin.peterson', 'python-dev']
    pr_nums = ['23143']
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue4225'
    versions = ['Python 2.6', 'Python 2.7']

    @benjaminp
    Copy link
    Contributor Author

    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.

    @benjaminp benjaminp added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 28, 2008
    @amauryfa
    Copy link
    Member

    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;

    @benjaminp
    Copy link
    Contributor Author

    This patch uses heap variables and tries to catch more places.

    @amauryfa
    Copy link
    Member

    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.

    @benjaminp
    Copy link
    Contributor Author

    Here's a patch that handles the parser module.

    @amauryfa
    Copy link
    Member

    The patch is good,
    except that you removed "static" before the function err_input (?)

    @benjaminp
    Copy link
    Contributor Author

    The removal of the "static" was a mistake. Fixed in r67066.

    @benjaminp
    Copy link
    Contributor Author

    This problem will still persist for anybody who uses PyParser_* APIs and
    then PyNode_Compile, but we can probably only document that.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants