(original) (raw)
On Wed, Feb 8, 2012 at 4:08 PM, Brett Cannon <brett@python.org> wrote:
On Wed, Feb 8, 2012 at 15:31, Terry Reedy <tjreedy@udel.edu> wrote:For top-level imports, unless \*all\* are made lazy, then there \*must\* be some indication in the code of whether to make it lazy or not.Not true; importlib would make it dead-simple to whitelist what modules to make lazy (e.g. your app code lazy but all stdlib stuff not, etc.).
There's actually only a few things stopping all imports from being lazy. �"from x import y" immediately de-lazies them, after all. �;-)
The main two reasons you wouldn't want imports to \*always\* be lazy are:
1\. Changing sys.path or other parameters between the import statement and the actual import
2\. ImportErrors are likewise deferred until point-of-use, so conditional importing with try/except would break.