-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for lazy imports #43
Comments
@Mandera any comment regarding this? |
Lazy imports would be very interesting if it could be implemented cleanly! I'm a little offended by your distaste of |
Good to hear that this would be a welcome feature! What would be your choice for a user facing design? I mentioned two. One could be a totally new function, e.g. If lazy is added to Regarding the actual implementation, I haven't really looked at how
Is my understanding correct? |
I like this one:
I'm afraid I have my doubts about a clean implementation for lazy imports though. I'm afraid we'd want 100% coverage if functional code were to go through this system
I think so yeah! |
Right, there's also one remaining issue for a use-case we can't handle: |
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
lazy_imports()
to explicitly make imports lazy.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 werefrom generalimport import optional_import
.The text was updated successfully, but these errors were encountered: