A topic closely related to optional imports are lazy imports. When a package is optional, it commonly happens that even though it is installed, it is not used for some process execution. In these cases, always importing all packages is a waste of resources. Implementing lazy imports can provide "startup time improvements up to 70% and memory-use reductions up to 40% on real-world Python CLIs".
Eventually lazy imports could become a native feature of python, but for the moment there are only long discussions and a rejected PEP 690. Thus, a package that provides it would certainly be welcome.
From my understanding adding lazy imports to generalimport would be relatively easy given what it already does. So I propose to add this as a feature.
Possible implementations
- Add a new function
lazy_imports() to explicitly make imports lazy.
- Modify the existing
generalimport() so that imports are always lazy.
Independent from this, from generalimport import generalimport does not look very nice or readable. Might be nicer if it were from generalimport import optional_import.
A topic closely related to optional imports are lazy imports. When a package is optional, it commonly happens that even though it is installed, it is not used for some process execution. In these cases, always importing all packages is a waste of resources. Implementing lazy imports can provide "startup time improvements up to 70% and memory-use reductions up to 40% on real-world Python CLIs".
Eventually lazy imports could become a native feature of python, but for the moment there are only long discussions and a rejected PEP 690. Thus, a package that provides it would certainly be welcome.
From my understanding adding lazy imports to
generalimportwould be relatively easy given what it already does. So I propose to add this as a feature.Possible implementations
lazy_imports()to explicitly make imports lazy.generalimport()so that imports are always lazy.Independent from this,
from generalimport import generalimportdoes not look very nice or readable. Might be nicer if it werefrom generalimport import optional_import.