by comex · 1y ago · 0 comments
I would have preferred a system where modules opt in to being lazy-loaded, with no extra syntax on the import side. That would simplify things since only large libraries would have to care about laziness. To be fair, in such a design, the interpreter would have to eagerly look up imports on the filesystem to decide whether they should be lazy-loaded. And there are probably other downsides I'm not thinking of.
In fact, half of the community basically uses only a modernized set of python 2.4 features and that's one of the beauties of the language. You don't need a lot to be productive, and if you want more, you can optionally reach for it.
It has worked very well for the last 2 decades and it will likely work again.
Same is true for C++.
In this specific case, I think a lazy load directive isn’t a bad addition. But one does need to be careful about adding new language features just because you have an active community.
Unless you are writing scripts or very simple stuff running side effects when modules are loaded should be avoided at all cost anyway.
oh, you want a "break my libraries" flag? :D
seriously, in theory lazy imports may be "transparent" for common use cases, but I've saw too many modules rely on the side effects of the importing, that I understand why they needed to make this a "double opt in" feature
But that's rare, and could be handled with existing workarounds.
Normally, a module needs to be eagerly imported if and only if it has side effects.