[Python-checkins] cpython (2.7): Issue #13557: Clarify effect of giving two different namespaces to exec or
terry.reedy
python-checkins at python.org
Sun Jul 8 23:53:50 CEST 2012
http://hg.python.org/cpython/rev/ab22ffa6fb2e
changeset: 78011:ab22ffa6fb2e
branch: 2.7
parent: 77995:45cd2d816f4d
user: Terry Jan Reedy <tjreedy at udel.edu>
date: Sun Jul 08 17:35:26 2012 -0400
summary:
Issue #13557: Clarify effect of giving two different namespaces to exec or
execfile().
files:
Doc/library/functions.rst | 5 ++++-
Doc/reference/simple_stmts.rst | 3 +++
Misc/NEWS | 4 +++-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -430,7 +430,10 @@
The arguments are a file name and two optional dictionaries. The file is parsed
and evaluated as a sequence of Python statements (similarly to a module) using
the *globals* and *locals* dictionaries as global and local namespace. If
- provided, *locals* can be any mapping object.
+ provided, *locals* can be any mapping object. Remember that at module level,
+ globals and locals are the same dictionary. If two separate objects are
+ passed as *globals* and *locals*, the code will be executed as if it were
+ embedded in a class definition.
.. versionchanged:: 2.4
formerly *locals* was required to be a dictionary.
diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst
--- a/Doc/reference/simple_stmts.rst
+++ b/Doc/reference/simple_stmts.rst
@@ -993,6 +993,9 @@
it should be a dictionary, which will be used for both the global and the local
variables. If two expressions are given, they are used for the global and local
variables, respectively. If provided, *locals* can be any mapping object.
+Remember that at module level, globals and locals are the same dictionary. If
+two separate objects are given as *globals* and *locals*, the code will be
+executed as if it were embedded in a class definition.
.. versionchanged:: 2.4
Formerly, *locals* was required to be a dictionary.
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -284,7 +284,9 @@
- Issue #14437: Fix building the _io module under Cygwin.
Documentation
--------------
+
+- Issue #13557: Clarify effect of giving two different namespaces to exec or
+ execfile().
- Issue #14034: added the argparse tutorial.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list