Skip to content

Unexpected behaviour of "compile" function #103375

Closed
@wrongnull

Description

@wrongnull

As already mentioned in #100185 builtin function compile does not take into account their enclosing scope. For instance:

x = 0

def a():
    print(x)
    x = 1

def b():
    source = "print(x)"
    co = compile(source, "", "exec")
    exec(co, globals(), locals())
    x = 1

Invocation of the first function works correctly and generates an exception, what can not be said about the second one. This example and one in issue above are also relevant for all currently supported python versions. I bet this can be fixed by promoting the symbol table of the scope to the function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions