load triggered in IPython upon any error raised?
dschult opened this issue · 2 comments
While trying to find a way to make lazy_loader.load work for subpackages (see #55), I discovered that IPython triggers a load of a lazily loaded package upon any exception being raised. A regular Python session does not.
Example:
import lazy_loader
mpl = lazy_loader.load("matplotlib")
print(type(mpl)) # result is <class 'importlib.util._LazyModule'>
raise Exception()
print(type(mpl)) # result is <class 'module'>The same code run in a python session does not trigger the loading of the lazy module.
I checked that nothing is calling the module's __getattr__ during that process. But something in IPython seems to be triggering the loading of lazily loaded modules.
Is this another reason to remove load from the package?
Python does all sorts of introspection into objects, so it's not surprising that, somewhere along the line, it triggers importing. I will close for now, unless you think we should fix this in lazy_loader itself.