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.

Author Peter Eastman
Recipients Peter Eastman, r.david.murray
Date 2015-08-05.20:33:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1438806839.14.0.828241700546.issue24800@psf.upfronthosting.co.za>
In-reply-to
Content
I don't believe that explanation is correct.  You can just as easily get the same problem without explicitly passing a map to exec().  For example:

def f():
    script = """
print(a)
print([a for i in range(5)])
    """
    a = 5
    exec(script)
    
f()

The documentation for exec() states, "In all cases, if the optional parts are omitted, the code is executed in the current scope."  Therefore the code above should be exactly equivalent to the following:

def f():
    a = 5
    print(a)
    print([a for i in range(5)])
    
f()

But the latter works and the former doesn't.  Contrary to the documentation, the code is clearly not being executed in the same scope.
History
Date User Action Args
2015-08-05 20:33:59Peter Eastmansetrecipients: + Peter Eastman, r.david.murray
2015-08-05 20:33:59Peter Eastmansetmessageid: <1438806839.14.0.828241700546.issue24800@psf.upfronthosting.co.za>
2015-08-05 20:33:59Peter Eastmanlinkissue24800 messages
2015-08-05 20:33:58Peter Eastmancreate