summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap.py9
-rw-r--r--Lib/test/test_import.py6
2 files changed, 13 insertions, 2 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 8ecc882..471b380 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 2e58199..7f2fad0 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -334,6 +334,12 @@ class ImportTests(unittest.TestCase):
del sys.path[0]
remove_files(TESTFN)
+ def test_bogus_fromlist(self):
+ try:
+ __import__('http', fromlist=['blah'])
+ except ImportError:
+ self.fail("fromlist must allow bogus names")
+
class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points