[Python-checkins] r74591 - in python/branches/py3k: Lib/importlib/_bootstrap.py Lib/importlib/test/import_/test_fromlist.py Misc/NEWS
brett.cannon
python-checkins at python.org
Sun Aug 30 20:28:46 CEST 2009
Author: brett.cannon
Date: Sun Aug 30 20:28:46 2009
New Revision: 74591
Log:
Allow importlib.__import__ to accept any iterable for fromlist. Discovered when
running importlib against test___all__.
Modified:
python/branches/py3k/Lib/importlib/_bootstrap.py
python/branches/py3k/Lib/importlib/test/import_/test_fromlist.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/py3k/Lib/importlib/_bootstrap.py (original)
+++ python/branches/py3k/Lib/importlib/_bootstrap.py Sun Aug 30 20:28:46 2009
@@ -943,6 +943,7 @@
# If a package was imported, try to import stuff from fromlist.
if hasattr(module, '__path__'):
if '*' in fromlist and hasattr(module, '__all__'):
+ fromlist = list(fromlist)
fromlist.remove('*')
fromlist.extend(module.__all__)
for x in (y for y in fromlist if not hasattr(module,y)):
Modified: python/branches/py3k/Lib/importlib/test/import_/test_fromlist.py
==============================================================================
--- python/branches/py3k/Lib/importlib/test/import_/test_fromlist.py (original)
+++ python/branches/py3k/Lib/importlib/test/import_/test_fromlist.py Sun Aug 30 20:28:46 2009
@@ -84,16 +84,23 @@
module = import_util.import_('pkg.mod', fromlist=[''])
self.assertEquals(module.__name__, 'pkg.mod')
- def test_using_star(self):
+ def basic_star_test(self, fromlist=['*']):
# [using *]
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
with util.import_state(meta_path=[mock]):
mock['pkg'].__all__ = ['module']
- module = import_util.import_('pkg', fromlist=['*'])
+ module = import_util.import_('pkg', fromlist=fromlist)
self.assertEquals(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'module'))
self.assertEqual(module.module.__name__, 'pkg.module')
+ def test_using_star(self):
+ # [using *]
+ self.basic_star_test()
+
+ def test_fromlist_as_tuple(self):
+ self.basic_star_test(('*',))
+
def test_star_with_others(self):
# [using * with others]
context = util.mock_modules('pkg.__init__', 'pkg.module1', 'pkg.module2')
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sun Aug 30 20:28:46 2009
@@ -68,6 +68,8 @@
Library
-------
+- Allow the fromlist passed into importlib.__import__ to be any iterable.
+
- Have importlib raise ImportError if None is found in sys.modules.
- Issue #6054: Do not normalize stored pathnames in tarfile.
More information about the Python-checkins
mailing list