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

ezio.melotti python-checkins at python.org
Mon May 9 05:44:48 CEST 2011


http://hg.python.org/cpython/rev/754bafe8db5f
changeset: 69956:754bafe8db5f
branch: 3.2
parent: 69951:0ea2c5866e7d
parent: 69955:3ab1eb027856
user: Ezio Melotti <ezio.melotti at gmail.com>
date: Mon May 09 06:43:14 2011 +0300
summary:
 #11910: merge with 3.1.
files:
 Lib/test/support.py | 12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -92,12 +92,14 @@
 def _save_and_remove_module(name, orig_modules):
 """Helper function to save and remove a module from sys.modules
 
- Return value is True if the module was in sys.modules and
- False otherwise."""
+ 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
+ __import__(name)
 saved = False
 else:
 del sys.modules[name]
@@ -107,8 +109,7 @@
 def _save_and_block_module(name, orig_modules):
 """Helper function to save and block a module in sys.modules
 
- Return value is True if the module was in sys.modules and
- False otherwise."""
+ Return True if the module was in sys.modules, False otherwise."""
 saved = True
 try:
 orig_modules[name] = sys.modules[name]
@@ -124,6 +125,7 @@
 the sys.modules cache is restored to its original state.
 
 Modules named in fresh are also imported anew if needed by the import.
+ If one of these modules can't be imported, None is returned.
 
 Importing of modules named in blocked is prevented while the fresh import
 takes place.
@@ -145,6 +147,8 @@
 if not _save_and_block_module(blocked_name, orig_modules):
 names_to_remove.append(blocked_name)
 fresh_module = importlib.import_module(name)
+ except ImportError:
+ fresh_module = None
 finally:
 for orig_name, module in orig_modules.items():
 sys.modules[orig_name] = module
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /