You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ordinarily, accessing attributes on a LazyModule triggers the import, but sometimes this can happen unexpectedly. One such case happens with the __file__ attribute. Here is a minimal example.
fail.py
raise ValueError('Boom!')
script.py
import inspect
from lazy_import import lazy_module
fail = lazy_module('fail')
frame = inspect.currentframe()
mod = inspect.getmodule(frame)
Running the above script triggers the import (and hence, the error). This results from inspect checking the __file__ attribute of every module in sys.modules, including fail. The behavior is undesirable since the user did not intentionally access any attribute of fail.
To fix this, one could simply add '__file__' to the list of exemptions in LazyModule.__getattribute__.
The text was updated successfully, but these errors were encountered:
Ordinarily, accessing attributes on a
LazyModule
triggers the import, but sometimes this can happen unexpectedly. One such case happens with the__file__
attribute. Here is a minimal example.fail.py
script.py
Running the above script triggers the import (and hence, the error). This results from
inspect
checking the__file__
attribute of every module insys.modules
, includingfail
. The behavior is undesirable since the user did not intentionally access any attribute offail
.To fix this, one could simply add
'__file__'
to the list of exemptions inLazyModule.__getattribute__
.The text was updated successfully, but these errors were encountered: