mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Allow importlib.__import__ to accept any iterable for fromlist. Discovered when
running importlib against test___all__.
This commit is contained in:
parent
12c3fc9343
commit
9e0e1a63c8
3 changed files with 12 additions and 2 deletions
|
@ -943,6 +943,7 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
|
||||||
# If a package was imported, try to import stuff from fromlist.
|
# If a package was imported, try to import stuff from fromlist.
|
||||||
if hasattr(module, '__path__'):
|
if hasattr(module, '__path__'):
|
||||||
if '*' in fromlist and hasattr(module, '__all__'):
|
if '*' in fromlist and hasattr(module, '__all__'):
|
||||||
|
fromlist = list(fromlist)
|
||||||
fromlist.remove('*')
|
fromlist.remove('*')
|
||||||
fromlist.extend(module.__all__)
|
fromlist.extend(module.__all__)
|
||||||
for x in (y for y in fromlist if not hasattr(module,y)):
|
for x in (y for y in fromlist if not hasattr(module,y)):
|
||||||
|
|
|
@ -84,16 +84,23 @@ class HandlingFromlist(unittest.TestCase):
|
||||||
module = import_util.import_('pkg.mod', fromlist=[''])
|
module = import_util.import_('pkg.mod', fromlist=[''])
|
||||||
self.assertEquals(module.__name__, 'pkg.mod')
|
self.assertEquals(module.__name__, 'pkg.mod')
|
||||||
|
|
||||||
def test_using_star(self):
|
def basic_star_test(self, fromlist=['*']):
|
||||||
# [using *]
|
# [using *]
|
||||||
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
|
with util.mock_modules('pkg.__init__', 'pkg.module') as mock:
|
||||||
with util.import_state(meta_path=[mock]):
|
with util.import_state(meta_path=[mock]):
|
||||||
mock['pkg'].__all__ = ['module']
|
mock['pkg'].__all__ = ['module']
|
||||||
module = import_util.import_('pkg', fromlist=['*'])
|
module = import_util.import_('pkg', fromlist=fromlist)
|
||||||
self.assertEquals(module.__name__, 'pkg')
|
self.assertEquals(module.__name__, 'pkg')
|
||||||
self.assertTrue(hasattr(module, 'module'))
|
self.assertTrue(hasattr(module, 'module'))
|
||||||
self.assertEqual(module.module.__name__, 'pkg.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):
|
def test_star_with_others(self):
|
||||||
# [using * with others]
|
# [using * with others]
|
||||||
context = util.mock_modules('pkg.__init__', 'pkg.module1', 'pkg.module2')
|
context = util.mock_modules('pkg.__init__', 'pkg.module1', 'pkg.module2')
|
||||||
|
|
|
@ -68,6 +68,8 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Allow the fromlist passed into importlib.__import__ to be any iterable.
|
||||||
|
|
||||||
- Have importlib raise ImportError if None is found in sys.modules.
|
- Have importlib raise ImportError if None is found in sys.modules.
|
||||||
|
|
||||||
- Issue #6054: Do not normalize stored pathnames in tarfile.
|
- Issue #6054: Do not normalize stored pathnames in tarfile.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue