lazy-imports
lazy-imports copied to clipboard
Attribute import support
Does the package support, or plan to support attribute-from-module imports?
From peps docs:
There are also third-party packages such as demandimport. These provide a “lazy module object” which delays its own import until first attribute access. This is not sufficient to make all imports lazy: imports such as from foo import a, b will still eagerly import the module foo since they immediately access an attribute from it. It also imposes noticeable runtime overhead on every module attribute access, since it requires a Python-level getattr or getattribute implementation.
Hi. I did not know about this pep before. So there were no plans. For me this pep reads like it might replace the functionality of lazy-imports one day.
A side thought on:
it might replace the functionality of lazy-imports one day.
If I were to guess I'd say it won't happen at least until around EOY. Native lazy imports were implemented in Python 3.12, released in October of 2023. To this date, coverage is not looking good: important libraries like grpcio have only recently released support for 3.11.
As for lazy-imports, do you find it worth the effort to support the development for the feature in topic?
As for lazy-imports, do you find it worth the effort to support the development for the feature in topic?
To be honest: I do not actively extend this tool at the moment. It is doing what I want it to do and thats it. The question if it is worth the effort must be answered by yourself. But we are always open for PRs. :-)
@teocns For PEP-690-style laziness, we would require a very different (and much more invasive!) approach. See for example this project: https://github.com/15r10nk/lazy-imports-lite#implementation
PEP-690 has been rejected already in 2022, by the way.