]> granicus.if.org Git - python/commitdiff
Issue #15471: Don't use mutable object as default values for the
authorBrett Cannon <brett@python.org>
Mon, 6 Aug 2012 20:34:44 +0000 (16:34 -0400)
committerBrett Cannon <brett@python.org>
Mon, 6 Aug 2012 20:34:44 +0000 (16:34 -0400)
parameters of importlib.__import__().

Doc/library/functions.rst
Doc/library/importlib.rst
Lib/importlib/_bootstrap.py
Misc/NEWS
Python/bltinmodule.c
Python/importlib.h

index e7ee51b330f26c242f908635c299c756d29cc7fb..212b4e1d22718c2b58f0848982021e36c1b0070e 100644 (file)
@@ -1443,7 +1443,7 @@ are always available.  They are listed here in alphabetical order.
       True
 
 
-.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=0)
+.. function:: __import__(name, globals=None, locals=None, fromlist=(), level=0)
 
    .. index::
       statement: import
index df05ec458960d4bd00c67b6a288caf2a44e159c2..2056b36f2b8cba0ce541d93cfac7d3758bb1155d 100644 (file)
@@ -63,7 +63,7 @@ Details on custom importers can be found in :pep:`302`.
 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.
 
index b9b35ec1e5b9d374700be134a75b64800fcffe96..4f61a5b4b331a51c91cc1dd6c0f6aa0ea4d1378f 100644 (file)
@@ -1587,7 +1587,7 @@ def _get_supported_file_loaders():
     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 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
     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
index 6f7b0fcc985eed2ca406a84b1e03bffc89fa8acf..4f590020f2b2e609fbfc67ea0aa14d38a7487094 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -77,6 +77,9 @@ Core and Builtins
 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)
index 3617b5a056017d9e598090954681a20167b5fb3e..e6511a1ae6bdc262e211cd51aa7bbb71092d6247 100644 (file)
@@ -195,7 +195,7 @@ builtin___import__(PyObject *self, PyObject *args, PyObject *kwds)
 }
 
 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\
index 0e6a457051d50edab4add50b0d72aea38d09fe80..36644d540008519019e7e88d5d01cc5b00463976 100644 (file)
@@ -57,8 +57,8 @@ unsigned char _Py_M__importlib[] = {
     100,110,0,132,0,0,90,65,0,100,125,0,100,45,0,100,
     111,0,100,112,0,132,2,0,90,66,0,100,113,0,100,114,
     0,132,0,0,90,67,0,100,115,0,100,116,0,132,0,0,
-    90,68,0,100,117,0,100,118,0,132,0,0,90,69,0,105,
-    0,0,105,0,0,103,0,0,100,45,0,100,119,0,100,120,
+    90,68,0,100,117,0,100,118,0,132,0,0,90,69,0,100,
+    125,0,100,125,0,102,0,0,100,45,0,100,119,0,100,120,
     0,132,4,0,90,70,0,100,121,0,100,122,0,132,0,0,
     90,71,0,100,123,0,100,124,0,132,0,0,90,72,0,100,
     125,0,83,40,127,0,0,0,117,83,1,0,0,67,111,114,
@@ -3912,69 +3912,72 @@ unsigned char _Py_M__importlib[] = {
     0,0,0,5,21,1,15,1,15,1,117,27,0,0,0,95,
     103,101,116,95,115,117,112,112,111,114,116,101,100,95,102,105,
     108,101,95,108,111,97,100,101,114,115,99,5,0,0,0,0,
-    0,0,0,8,0,0,0,5,0,0,0,67,0,0,0,115,
-    203,0,0,0,124,4,0,100,1,0,107,2,0,114,27,0,
-    116,0,0,124,0,0,131,1,0,125,5,0,110,30,0,116,
-    1,0,124,1,0,131,1,0,125,6,0,116,0,0,124,0,
-    0,124,6,0,124,4,0,131,3,0,125,5,0,124,3,0,
-    115,183,0,124,4,0,100,1,0,107,2,0,114,98,0,116,
-    0,0,124,0,0,106,2,0,100,2,0,131,1,0,100,1,
-    0,25,131,1,0,83,124,0,0,115,108,0,124,5,0,83,
-    116,3,0,124,0,0,131,1,0,116,3,0,124,0,0,106,
-    2,0,100,2,0,131,1,0,100,1,0,25,131,1,0,24,
-    125,7,0,116,4,0,106,5,0,124,5,0,106,6,0,100,
-    3,0,116,3,0,124,5,0,106,6,0,131,1,0,124,7,
-    0,24,133,2,0,25,25,83,110,16,0,116,7,0,124,5,
-    0,124,3,0,116,0,0,131,3,0,83,100,3,0,83,40,
-    4,0,0,0,117,214,1,0,0,73,109,112,111,114,116,32,
-    97,32,109,111,100,117,108,101,46,10,10,32,32,32,32,84,
-    104,101,32,39,103,108,111,98,97,108,115,39,32,97,114,103,
-    117,109,101,110,116,32,105,115,32,117,115,101,100,32,116,111,
-    32,105,110,102,101,114,32,119,104,101,114,101,32,116,104,101,
-    32,105,109,112,111,114,116,32,105,115,32,111,99,99,117,114,
-    105,110,103,32,102,114,111,109,10,32,32,32,32,116,111,32,
-    104,97,110,100,108,101,32,114,101,108,97,116,105,118,101,32,
-    105,109,112,111,114,116,115,46,32,84,104,101,32,39,108,111,
-    99,97,108,115,39,32,97,114,103,117,109,101,110,116,32,105,
-    115,32,105,103,110,111,114,101,100,46,32,84,104,101,10,32,
-    32,32,32,39,102,114,111,109,108,105,115,116,39,32,97,114,
-    103,117,109,101,110,116,32,115,112,101,99,105,102,105,101,115,
-    32,119,104,97,116,32,115,104,111,117,108,100,32,101,120,105,
-    115,116,32,97,115,32,97,116,116,114,105,98,117,116,101,115,
-    32,111,110,32,116,104,101,32,109,111,100,117,108,101,10,32,
-    32,32,32,98,101,105,110,103,32,105,109,112,111,114,116,101,
-    100,32,40,101,46,103,46,32,96,96,102,114,111,109,32,109,
-    111,100,117,108,101,32,105,109,112,111,114,116,32,60,102,114,
-    111,109,108,105,115,116,62,96,96,41,46,32,32,84,104,101,
-    32,39,108,101,118,101,108,39,10,32,32,32,32,97,114,103,
-    117,109,101,110,116,32,114,101,112,114,101,115,101,110,116,115,
-    32,116,104,101,32,112,97,99,107,97,103,101,32,108,111,99,
-    97,116,105,111,110,32,116,111,32,105,109,112,111,114,116,32,
-    102,114,111,109,32,105,110,32,97,32,114,101,108,97,116,105,
-    118,101,10,32,32,32,32,105,109,112,111,114,116,32,40,101,
-    46,103,46,32,96,96,102,114,111,109,32,46,46,112,107,103,
-    32,105,109,112,111,114,116,32,109,111,100,96,96,32,119,111,
-    117,108,100,32,104,97,118,101,32,97,32,39,108,101,118,101,
-    108,39,32,111,102,32,50,41,46,10,10,32,32,32,32,105,
-    0,0,0,0,117,1,0,0,0,46,78,40,8,0,0,0,
-    117,11,0,0,0,95,103,99,100,95,105,109,112,111,114,116,
-    117,17,0,0,0,95,99,97,108,99,95,95,95,112,97,99,
-    107,97,103,101,95,95,117,9,0,0,0,112,97,114,116,105,
-    116,105,111,110,117,3,0,0,0,108,101,110,117,3,0,0,
-    0,115,121,115,117,7,0,0,0,109,111,100,117,108,101,115,
-    117,8,0,0,0,95,95,110,97,109,101,95,95,117,16,0,
-    0,0,95,104,97,110,100,108,101,95,102,114,111,109,108,105,
-    115,116,40,8,0,0,0,117,4,0,0,0,110,97,109,101,
-    117,7,0,0,0,103,108,111,98,97,108,115,117,6,0,0,
-    0,108,111,99,97,108,115,117,8,0,0,0,102,114,111,109,
-    108,105,115,116,117,5,0,0,0,108,101,118,101,108,117,6,
-    0,0,0,109,111,100,117,108,101,117,7,0,0,0,112,97,
-    99,107,97,103,101,117,7,0,0,0,99,117,116,95,111,102,
-    102,40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,
-    60,102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,
-    98,46,95,98,111,111,116,115,116,114,97,112,62,117,10,0,
-    0,0,95,95,105,109,112,111,114,116,95,95,54,6,0,0,
-    115,24,0,0,0,0,11,12,1,15,2,12,1,18,1,6,
+    0,0,0,9,0,0,0,5,0,0,0,67,0,0,0,115,
+    227,0,0,0,124,4,0,100,1,0,107,2,0,114,27,0,
+    116,0,0,124,0,0,131,1,0,125,5,0,110,54,0,124,
+    1,0,100,3,0,107,9,0,114,45,0,124,1,0,110,3,
+    0,105,0,0,125,6,0,116,2,0,124,6,0,131,1,0,
+    125,7,0,116,0,0,124,0,0,124,7,0,124,4,0,131,
+    3,0,125,5,0,124,3,0,115,207,0,124,4,0,100,1,
+    0,107,2,0,114,122,0,116,0,0,124,0,0,106,3,0,
+    100,2,0,131,1,0,100,1,0,25,131,1,0,83,124,0,
+    0,115,132,0,124,5,0,83,116,4,0,124,0,0,131,1,
+    0,116,4,0,124,0,0,106,3,0,100,2,0,131,1,0,
+    100,1,0,25,131,1,0,24,125,8,0,116,5,0,106,6,
+    0,124,5,0,106,7,0,100,3,0,116,4,0,124,5,0,
+    106,7,0,131,1,0,124,8,0,24,133,2,0,25,25,83,
+    110,16,0,116,8,0,124,5,0,124,3,0,116,0,0,131,
+    3,0,83,100,3,0,83,40,4,0,0,0,117,214,1,0,
+    0,73,109,112,111,114,116,32,97,32,109,111,100,117,108,101,
+    46,10,10,32,32,32,32,84,104,101,32,39,103,108,111,98,
+    97,108,115,39,32,97,114,103,117,109,101,110,116,32,105,115,
+    32,117,115,101,100,32,116,111,32,105,110,102,101,114,32,119,
+    104,101,114,101,32,116,104,101,32,105,109,112,111,114,116,32,
+    105,115,32,111,99,99,117,114,105,110,103,32,102,114,111,109,
+    10,32,32,32,32,116,111,32,104,97,110,100,108,101,32,114,
+    101,108,97,116,105,118,101,32,105,109,112,111,114,116,115,46,
+    32,84,104,101,32,39,108,111,99,97,108,115,39,32,97,114,
+    103,117,109,101,110,116,32,105,115,32,105,103,110,111,114,101,
+    100,46,32,84,104,101,10,32,32,32,32,39,102,114,111,109,
+    108,105,115,116,39,32,97,114,103,117,109,101,110,116,32,115,
+    112,101,99,105,102,105,101,115,32,119,104,97,116,32,115,104,
+    111,117,108,100,32,101,120,105,115,116,32,97,115,32,97,116,
+    116,114,105,98,117,116,101,115,32,111,110,32,116,104,101,32,
+    109,111,100,117,108,101,10,32,32,32,32,98,101,105,110,103,
+    32,105,109,112,111,114,116,101,100,32,40,101,46,103,46,32,
+    96,96,102,114,111,109,32,109,111,100,117,108,101,32,105,109,
+    112,111,114,116,32,60,102,114,111,109,108,105,115,116,62,96,
+    96,41,46,32,32,84,104,101,32,39,108,101,118,101,108,39,
+    10,32,32,32,32,97,114,103,117,109,101,110,116,32,114,101,
+    112,114,101,115,101,110,116,115,32,116,104,101,32,112,97,99,
+    107,97,103,101,32,108,111,99,97,116,105,111,110,32,116,111,
+    32,105,109,112,111,114,116,32,102,114,111,109,32,105,110,32,
+    97,32,114,101,108,97,116,105,118,101,10,32,32,32,32,105,
+    109,112,111,114,116,32,40,101,46,103,46,32,96,96,102,114,
+    111,109,32,46,46,112,107,103,32,105,109,112,111,114,116,32,
+    109,111,100,96,96,32,119,111,117,108,100,32,104,97,118,101,
+    32,97,32,39,108,101,118,101,108,39,32,111,102,32,50,41,
+    46,10,10,32,32,32,32,105,0,0,0,0,117,1,0,0,
+    0,46,78,40,9,0,0,0,117,11,0,0,0,95,103,99,
+    100,95,105,109,112,111,114,116,117,4,0,0,0,78,111,110,
+    101,117,17,0,0,0,95,99,97,108,99,95,95,95,112,97,
+    99,107,97,103,101,95,95,117,9,0,0,0,112,97,114,116,
+    105,116,105,111,110,117,3,0,0,0,108,101,110,117,3,0,
+    0,0,115,121,115,117,7,0,0,0,109,111,100,117,108,101,
+    115,117,8,0,0,0,95,95,110,97,109,101,95,95,117,16,
+    0,0,0,95,104,97,110,100,108,101,95,102,114,111,109,108,
+    105,115,116,40,9,0,0,0,117,4,0,0,0,110,97,109,
+    101,117,7,0,0,0,103,108,111,98,97,108,115,117,6,0,
+    0,0,108,111,99,97,108,115,117,8,0,0,0,102,114,111,
+    109,108,105,115,116,117,5,0,0,0,108,101,118,101,108,117,
+    6,0,0,0,109,111,100,117,108,101,117,8,0,0,0,103,
+    108,111,98,97,108,115,95,117,7,0,0,0,112,97,99,107,
+    97,103,101,117,7,0,0,0,99,117,116,95,111,102,102,40,
+    0,0,0,0,40,0,0,0,0,117,29,0,0,0,60,102,
+    114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,46,
+    95,98,111,111,116,115,116,114,97,112,62,117,10,0,0,0,
+    95,95,105,109,112,111,114,116,95,95,54,6,0,0,115,26,
+    0,0,0,0,11,12,1,15,2,24,1,12,1,18,1,6,
     3,12,1,23,1,6,1,4,2,35,1,40,2,117,10,0,
     0,0,95,95,105,109,112,111,114,116,95,95,99,2,0,0,
     0,0,0,0,0,14,0,0,0,13,0,0,0,67,0,0,
@@ -4052,7 +4055,7 @@ unsigned char _Py_M__importlib[] = {
     40,0,0,0,0,40,0,0,0,0,117,29,0,0,0,60,
     102,114,111,122,101,110,32,105,109,112,111,114,116,108,105,98,
     46,95,98,111,111,116,115,116,114,97,112,62,117,9,0,0,
-    0,60,103,101,110,101,120,112,114,62,112,6,0,0,115,2,
+    0,60,103,101,110,101,120,112,114,62,113,6,0,0,115,2,
     0,0,0,6,0,117,25,0,0,0,95,115,101,116,117,112,
     46,60,108,111,99,97,108,115,62,46,60,103,101,110,101,120,
     112,114,62,105,0,0,0,0,117,7,0,0,0,69,77,88,
@@ -4107,7 +4110,7 @@ unsigned char _Py_M__importlib[] = {
     109,111,100,117,108,101,40,0,0,0,0,40,0,0,0,0,
     117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,
     111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,
-    112,62,117,6,0,0,0,95,115,101,116,117,112,85,6,0,
+    112,62,117,6,0,0,0,95,115,101,116,117,112,86,6,0,
     0,115,88,0,0,0,0,9,6,1,6,2,19,1,15,1,
     16,2,13,1,13,1,15,1,18,2,13,1,20,2,48,1,
     19,2,31,1,10,1,15,1,13,1,4,2,3,1,15,2,
@@ -4150,7 +4153,7 @@ unsigned char _Py_M__importlib[] = {
     111,97,100,101,114,115,40,0,0,0,0,40,0,0,0,0,
     117,29,0,0,0,60,102,114,111,122,101,110,32,105,109,112,
     111,114,116,108,105,98,46,95,98,111,111,116,115,116,114,97,
-    112,62,117,8,0,0,0,95,105,110,115,116,97,108,108,153,
+    112,62,117,8,0,0,0,95,105,110,115,116,97,108,108,154,
     6,0,0,115,16,0,0,0,0,2,13,1,9,1,28,1,
     16,1,16,1,15,1,19,1,117,8,0,0,0,95,105,110,
     115,116,97,108,108,78,40,3,0,0,0,117,3,0,0,0,
@@ -4252,5 +4255,5 @@ unsigned char _Py_M__importlib[] = {
     12,18,12,11,12,13,19,57,19,54,19,50,19,82,22,124,
     19,29,25,38,25,24,19,41,19,55,19,18,19,81,19,135,
     19,13,12,9,12,17,12,17,6,2,12,46,12,13,18,24,
-    12,23,12,15,12,11,24,31,12,68,
+    12,23,12,15,12,11,24,32,12,68,
 };