[Python-Dev] About closures creates in exec

Andrea Griffini agriff at tin.it
Wed Aug 12 21:05:50 CEST 2015

Is it intended that closures created in exec statement/function cannot see
locals if the exec was provided a locals dictionary?

This code gives an error ("foo" is not found during lambda execution):

    exec("def foo(x): return x\n\n(lambda x:foo(x))(0)", globals(), {})

while executes normally with

    exec("def foo(x): return x\n\n(lambda x:foo(x))(0)")

Is this the expected behavior? If so where is it documented?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150812/1f9ab8ac/attachment.html>

More information about the Python-Dev mailing list