[issue26205] Better specify number of nested scopes

Terry J. Reedy report at bugs.python.org
Mon Jul 6 05:49:06 EDT 2020


Terry J. Reedy <tjreedy at udel.edu> added the comment:

Since you ask, here is a extended summary of namespaces. There is one built-in namespace.  There is one global namespace for each module, which is also the local namespace for top level code in that module.  There is one local namespace for each class and function.  There is one nonlocal namespace for each nested function.  "At any time during execution" (the beginning of the doc sentence targeted by this issue), there are 3 or maybe 4 namespaces accessible with simple undotted names. 

Module global and class local namespaces, including nested classes, are accessible from without the object with dotted names.  There are rules for class and method code about access to superclass namespaces.  Function locals are not necessarily accessible with standard python code, but at least in cpython, local names can be accessed via code objects.  Default parameter values and current nonlocal values, when set, can be accessed via function objects.  Dotted names are discussed elsewhere in the tutorial, while function and code object introspection is out of scope there.  (And off topic for this issue ;-).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26205>
_______________________________________


More information about the Python-bugs-list mailing list