[Python-checkins] cpython (merge 3.1 -> 3.2): Merge with 3.1.

ezio.melotti python-checkins at python.org
Sat May 14 05:24:32 CEST 2011


http://hg.python.org/cpython/rev/688962b8a175
changeset:   70082:688962b8a175
branch:      3.2
parent:      70078:b340d1577dc5
parent:      70081:9b7bfe86f04d
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat May 14 06:23:20 2011 +0300
summary:
  Merge with 3.1.

files:
  Lib/test/support.py |  16 ++++++----------
  1 files changed, 6 insertions(+), 10 deletions(-)


diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -92,19 +92,15 @@
 def _save_and_remove_module(name, orig_modules):
     """Helper function to save and remove a module from sys.modules
 
-       Return True if the module was in sys.modules, False otherwise.
        Raise ImportError if the module can't be imported."""
-    saved = True
-    try:
-        orig_modules[name] = sys.modules[name]
-    except KeyError:
-        # try to import the module and raise an error if it can't be imported
+    # try to import the module and raise an error if it can't be imported
+    if name not in sys.modules:
         __import__(name)
-        saved = False
-    else:
         del sys.modules[name]
-    return saved
-
+    for modname in list(sys.modules):
+        if modname == name or modname.startswith(name + '.'):
+            orig_modules[modname] = sys.modules[modname]
+            del sys.modules[modname]
 
 def _save_and_block_module(name, orig_modules):
     """Helper function to save and block a module in sys.modules

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


More information about the Python-checkins mailing list