mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15111: When a module was imported using a 'from import'
statement (e.g. ``from distutils import msvc9compiler``) that triggers an ImportError of its own (e.g. the non-existence of winreg), let that exception propagate instead of raising a generic ImportError for the module being requested (e.g. msvc9compiler).
This commit is contained in:
parent
c4618e33b2
commit
461c813164
4 changed files with 410 additions and 422 deletions
|
@ -1459,16 +1459,14 @@ def _handle_fromlist(module, fromlist, import_):
|
|||
# The hell that is fromlist ...
|
||||
# If a package was imported, try to import stuff from fromlist.
|
||||
if hasattr(module, '__path__'):
|
||||
if '*' in fromlist and hasattr(module, '__all__'):
|
||||
if '*' in fromlist:
|
||||
fromlist = list(fromlist)
|
||||
fromlist.remove('*')
|
||||
fromlist.extend(module.__all__)
|
||||
if hasattr(module, '__all__'):
|
||||
fromlist.extend(module.__all__)
|
||||
for x in fromlist:
|
||||
if not hasattr(module, x):
|
||||
try:
|
||||
import_('{}.{}'.format(module.__name__, x))
|
||||
except ImportError:
|
||||
pass
|
||||
import_('{}.{}'.format(module.__name__, x))
|
||||
return module
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue