From a6ce4fd426cb9df0e4816a627c79aff0fc6ecf63 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 10 Oct 2012 19:03:46 -0400 Subject: Closes issue #15111: Calling __import__ with a module specified in fromlist which causes its own ImportError (e.g. the module tries to import a non-existent module) should have that exception propagate. --- Lib/importlib/_bootstrap.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Lib/importlib/_bootstrap.py') diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 98361a77b9..fad95a620e 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1602,19 +1602,19 @@ def _handle_fromlist(module, fromlist, import_): fromlist.extend(module.__all__) for x in fromlist: if not hasattr(module, x): + from_name = '{}.{}'.format(module.__name__, x) try: - _call_with_frames_removed(import_, - '{}.{}'.format(module.__name__, x)) + _call_with_frames_removed(import_, from_name) except ImportError as exc: # Backwards-compatibility dictates we ignore failed # imports triggered by fromlist for modules that don't # exist. # TODO(brett): In Python 3.4, have import raise # ModuleNotFound and catch that. - if hasattr(exc, '_not_found') and exc._not_found: - pass - else: - raise + if getattr(exc, '_not_found', False): + if exc.name == from_name: + continue + raise return module -- cgit v1.2.1