[Python-Dev] requirements for moving __import__ over to importlib?

PJ Eby pje at telecommunity.com
Thu Feb 9 02:28:56 CET 2012


On Wed, Feb 8, 2012 at 4:08 PM, Brett Cannon <brett at python.org> wrote:

>
> On Wed, Feb 8, 2012 at 15:31, Terry Reedy <tjreedy at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120208/ca56fb26/attachment.html>


More information about the Python-Dev mailing list