<br><br><div class="gmail_quote">On Wed, Feb 8, 2012 at 20:28, PJ Eby <span dir="ltr"><<a href="mailto:pje@telecommunity.com">pje@telecommunity.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div class="im">On Wed, Feb 8, 2012 at 4:08 PM, Brett Cannon <span dir="ltr"><<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>></span> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><div class="gmail_quote"><div><div class="im">On Wed, Feb 8, 2012 at 15:31, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br></div><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>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.</div></blockquote><div><br></div></div></div><div class="im"><div>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.).</div>
</div></div></blockquote><div><br></div><div>There's actually only a few things stopping all imports from being lazy. "from x import y" immediately de-lazies them, after all. ;-)</div><div><br></div><div>
The main two reasons you wouldn't want imports to *always* be lazy are:</div>
<div><br></div><div>1. Changing sys.path or other parameters between the import statement and the actual import</div><div>2. ImportErrors are likewise deferred until point-of-use, so conditional importing with try/except would break.</div>
</div>
</blockquote></div><div><br></div><div>This actually depends on the type of ImportError. My current solution actually would trigger an ImportError at the import statement if no finder could locate the module. But if some ImportError was raised because of some other issue during load then that would come up at first use.</div>