[Python-checkins] r74586 - in python/branches/release31-maint: Lib/importlib/_bootstrap.py Lib/importlib/test/import_/test_caching.py Misc/NEWS
brett.cannon
python-checkins at python.org
Sun Aug 30 06:29:47 CEST 2009
Author: brett.cannon
Date: Sun Aug 30 06:29:47 2009
New Revision: 74586
Log:
Merged revisions 74584 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r74584 | brett.cannon | 2009-08-29 20:47:36 -0700 (Sat, 29 Aug 2009) | 3 lines
Have importlib raise ImportError if None is found in sys.modules. This matches
current import semantics.
........
Modified:
python/branches/release31-maint/ (props changed)
python/branches/release31-maint/Lib/importlib/_bootstrap.py
python/branches/release31-maint/Lib/importlib/test/import_/test_caching.py
python/branches/release31-maint/Misc/NEWS
Modified: python/branches/release31-maint/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/release31-maint/Lib/importlib/_bootstrap.py (original)
+++ python/branches/release31-maint/Lib/importlib/_bootstrap.py Sun Aug 30 06:29:47 2009
@@ -860,7 +860,12 @@
name = package[:dot]
with _ImportLockContext():
try:
- return sys.modules[name]
+ module = sys.modules[name]
+ if module is None:
+ message = ("import of {} halted; "
+ "None in sys.modules".format(name))
+ raise ImportError(message)
+ return module
except KeyError:
pass
parent = name.rpartition('.')[0]
Modified: python/branches/release31-maint/Lib/importlib/test/import_/test_caching.py
==============================================================================
--- python/branches/release31-maint/Lib/importlib/test/import_/test_caching.py (original)
+++ python/branches/release31-maint/Lib/importlib/test/import_/test_caching.py Sun Aug 30 06:29:47 2009
@@ -17,15 +17,25 @@
loader returns) [from cache on return]. This also applies to imports of
things contained within a package and thus get assigned as an attribute
[from cache to attribute] or pulled in thanks to a fromlist import
- [from cache for fromlist].
+ [from cache for fromlist]. But if sys.modules contains None then
+ ImportError is raised [None in cache].
"""
def test_using_cache(self):
# [use cache]
module_to_use = "some module found!"
- sys.modules['some_module'] = module_to_use
- module = import_util.import_('some_module')
- self.assertEqual(id(module_to_use), id(module))
+ with util.uncache(module_to_use):
+ sys.modules['some_module'] = module_to_use
+ module = import_util.import_('some_module')
+ self.assertEqual(id(module_to_use), id(module))
+
+ def test_None_in_cache(self):
+ #[None in cache]
+ name = 'using_None'
+ with util.uncache(name):
+ sys.modules[name] = None
+ with self.assertRaises(ImportError):
+ import_util.import_(name)
def create_mock(self, *names, return_=None):
mock = util.mock_modules(*names)
Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS (original)
+++ python/branches/release31-maint/Misc/NEWS Sun Aug 30 06:29:47 2009
@@ -50,6 +50,9 @@
Library
-------
+- Have importlib raise ImportError if None is found in sys.modules for a
+ module.
+
- Issue #6794: Fix Decimal.compare_total and Decimal.compare_total_mag: NaN
payloads are now ordered by integer value rather than lexicographically.
More information about the Python-checkins
mailing list