Add importlib.set_lazy_imports() to enable Lazy Imports in runtime.
Test Plan
If we start Python without Lazy Imports, we can use importlib.set_lazy_imports() to enable Lazy Imports in runtime. That is to say, after running importlib.set_lazy_imports(), every import should be lazy.
If Lazy Imports is enabled at the beginning, the behavior should not change.
importlib.set_lazy_import() should not have any argument.
No matter with or without -L, if we give it any argument, it will return the error message.
>>> importlib.set_lazy_imports(123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: set_lazy_imports() takes 0 positional arguments but 1 was given
Summary
Add
importlib.set_lazy_imports()
to enable Lazy Imports in runtime.Test Plan
importlib.set_lazy_imports()
to enable Lazy Imports in runtime. That is to say, after runningimportlib.set_lazy_imports()
, every import should be lazy.Start without Lazy Imports
Run
If we import
json
, it should not be lazy.Then, we use
importlib.set_lazy_imports()
to enable Lazy Imports. If we importmath
now, it should be lazy.If we use
math.pi
, it would be loaded.Start with Lazy Imports
Run
If we import
math
, it should be lazy because we starts with-L
.If we use
math.pi
, it would be loaded.If we use
importlib.set_lazy_imports()
, the behavior will not change. If we importjson
immediately,json
is still lazy.Wrong numbers of arguments
importlib.set_lazy_import()
should not have any argument. No matter with or without-L
, if we give it any argument, it will return the error message.