Preferences

I would gladly take a command line flag that I can pass to python that makes all module loading lazy.

Unless you are writing scripts or very simple stuff running side effects when modules are loaded should be avoided at all cost anyway.


The PEP includes the ability to enable (or disable) lazy imports globally via a command-line flag or environment variable, in addition to the import syntax.
> I would gladly take a command line flag that I can pass to python that makes all module loading lazy.

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

That's already part of the PIP. There is a flag to enable lazy imports for all possible imports.
You can do it today with a few lines of code, although the implementation I show is not particularly robust (since it works by metaprogramming the import system, of course other code could interfere): https://www.hackerneue.com/item?id=45467489

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal