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 eryksun
Recipients Peter Eastman, docs@python, eryksun, r.david.murray
Date 2021-03-07.18:17:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615141050.03.0.433766085511.issue24800@roundup.psfhosted.org>
In-reply-to
Content
So there are a couple things to clarify here. When the documentation says "if the optional parts are omitted, the code is executed in the current scope", I think it should explicitly state that this is equivalent to calling exec(object, globals(), locals()). This should help to disabuse the reader of any assumption that the compiled code will extend the nested scoping (i.e. lexical closures) of the calling context.

When it says that if "exec gets two separate objects as globals and locals, the code will be executed as if it were embedded in a class definition", I think this can be misleading. exec() compiles top-level code. It extends module-like execution, allowing globals and locals to differ and defaulting to the current scope. This sharply contrasts to code that's compiled for a `class` statement in the same context.
History
Date User Action Args
2021-03-07 18:17:30eryksunsetrecipients: + eryksun, r.david.murray, docs@python, Peter Eastman
2021-03-07 18:17:30eryksunsetmessageid: <1615141050.03.0.433766085511.issue24800@roundup.psfhosted.org>
2021-03-07 18:17:30eryksunlinkissue24800 messages
2021-03-07 18:17:29eryksuncreate