mirror of
https://github.com/python/cpython.git
synced 2025-10-06 15:11:58 +00:00
Issue #15715: Ignore failed imports triggered by the use of fromlist.
When the fromlist argument is specified for __import__() and the attribute doesn't already exist, an import is attempted. If that fails (e.g. module doesn't exist), the ImportError will now be silenced (for backwards-compatibility). This *does not* affect ``from ... import ...`` statements. Thanks to Eric Snow for the patch and Simon Feltman for reporting the regression.
This commit is contained in:
parent
b391b24efe
commit
7385adc84c
4 changed files with 474 additions and 458 deletions
|
@ -1573,8 +1573,13 @@ def _handle_fromlist(module, fromlist, import_):
|
|||
fromlist.extend(module.__all__)
|
||||
for x in fromlist:
|
||||
if not hasattr(module, x):
|
||||
_call_with_frames_removed(import_,
|
||||
'{}.{}'.format(module.__name__, x))
|
||||
try:
|
||||
_call_with_frames_removed(import_,
|
||||
'{}.{}'.format(module.__name__, x))
|
||||
except ImportError:
|
||||
# Backwards-compatibility dictates we ignore failed
|
||||
# imports triggered by fromlist.
|
||||
pass
|
||||
return module
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue