Skip to content

Commit 0049fc3

Browse files
committed
Be more robust against custom import failures (e.g., from ome_types).
1 parent 3beefd7 commit 0049fc3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ipython_autoimport.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ def __getattr__(self, name):
123123
import_target = "{}.{}".format(self.__name__, name)
124124
try:
125125
submodule = importlib.import_module(import_target)
126-
except getattr(builtins, "ModuleNotFoundError", ImportError):
127-
pass # Py<3.6.
126+
except ModuleNotFoundError:
127+
pass
128+
except Exception as exc:
129+
# In theory we should just catch ModuleNotFoundError, but
130+
# ome_types (inaccurately) raises ImportError instead.
131+
_report(self.__ipython, "import {} caused {}: {}".format(
132+
import_target, type(exc).__name__, exc))
128133
else:
129134
_report(self.__ipython, "import {}".format(import_target))
130135
return _make_submodule_autoimporter_module(

0 commit comments

Comments
 (0)