[Python-ideas] lazy import via __future__ or compiler analysis

Chris Angelico rosuav at gmail.com
Fri Sep 8 12:02:40 EDT 2017


On Sat, Sep 9, 2017 at 1:27 AM, Joshua Morton <joshua.morton13 at gmail.com> wrote:
> As a result of this, you can't even know if an import is safe, because that
> module may have side effects. That is, the module foo.py:
>
>     import bar
>
> isn't known to be lazy, because bar may import and start the logging module,
> as an example.

Laziness has to be complete - or, looking the other way, eager
importing is infectious. For foo to be lazy, bar also has to be lazy;
if you don't know for absolute certain that bar is lazy-loadable, then
you assume it isn't, and foo becomes eagerly loaded.

ChrisA


More information about the Python-ideas mailing list