Closed
Description
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 = 1Invocation 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.