[Python-checkins] cpython: Issue #15471: Don't use mutable object as default values for the

brett.cannon python-checkins at python.org
Mon Aug 6 22:34:55 CEST 2012


http://hg.python.org/cpython/rev/4240282a9f4a
changeset:   78456:4240282a9f4a
parent:      78454:0d6eea2330d0
user:        Brett Cannon <brett at python.org>
date:        Mon Aug 06 16:34:44 2012 -0400
summary:
  Issue #15471: Don't use mutable object as default values for the
parameters of importlib.__import__().

files:
  Doc/library/functions.rst   |    2 +-
  Doc/library/importlib.rst   |    2 +-
  Lib/importlib/_bootstrap.py |    5 +-
  Misc/NEWS                   |    3 +
  Python/bltinmodule.c        |    2 +-
  Python/importlib.h          |  141 ++++++++++++-----------
  6 files changed, 81 insertions(+), 74 deletions(-)


diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1443,7 +1443,7 @@
       True
 
 
-.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=0)
+.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0)
 
    .. index::
       statement: import
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -63,7 +63,7 @@
 Functions
 ---------
 
-.. function:: __import__(name, globals={}, locals={}, fromlist=list(), level=0)
+.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0)
 
     An implementation of the built-in :func:`__import__` function.
 
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1587,7 +1587,7 @@
     return [extensions, source, bytecode]
 
 
-def __import__(name, globals={}, locals={}, fromlist=[], level=0):
+def __import__(name, globals=None, locals=None, fromlist=(), level=0):
     """Import a module.
 
     The 'globals' argument is used to infer where the import is occuring from
@@ -1601,7 +1601,8 @@
     if level == 0:
         module = _gcd_import(name)
     else:
-        package = _calc___package__(globals)
+        globals_ = globals if globals is not None else {}
+        package = _calc___package__(globals_)
         module = _gcd_import(name, package, level)
     if not fromlist:
         # Return up to the first dot in 'name'. This is complicated by the fact
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -77,6 +77,9 @@
 Library
 -------
 
+- Issue #15471: Do not use mutable objects as defaults for
+  importlib.__import__().
+
 - Issue #15559: To avoid a problematic failure mode when passed to the bytes
   constructor, objects in the ipaddress module no longer implement __index__
   (they still implement __int__ as appropriate)
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -195,7 +195,7 @@
 }
 
 PyDoc_STRVAR(import_doc,
-"__import__(name, globals={}, locals={}, fromlist=[], level=0) -> module\n\
+"__import__(name, globals=None, locals=None, fromlist=(), level=0) -> module\n\
 \n\
 Import a module. Because this function is meant for use by the Python\n\
 interpreter and not for general use it is better to use\n\
diff --git a/Python/importlib.h b/Python/importlib.h
--- a/Python/importlib.h
+++ b/Python/importlib.h
[stripped]

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list