Eryk Sun <eryk...@gmail.com> added the comment:

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.

----------
type: behavior -> enhancement
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.4, Python 3.5, Python 
3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue24800>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to