[Python-3000] Interest in PEP for callbacks on module import
Phillip J. Eby
pje at telecommunity.com
Sun Dec 9 01:05:26 CET 2007
At 12:37 PM 12/9/2007 +1300, Greg Ewing wrote:
>Phillip J. Eby wrote:
>
> > Lazy importing is putting a module object into sys.modules, but not
> > loading its contents until you attempt to get or set a module attribute.
>
>How is that expected to be useful? If you're not going
>to access any attributes of a module, why can you simply
>not import it in the first place?
It speeds application startup by deferring imports until first use,
and *without* requiring *every* function using the imported module(s)
to include an import statement.
Once the module is actually loaded, attribute access is as fast as it
normally is (because the custom module type then uses the normal
object.__getattribute__ and object.__setattr__ methods once again.
>It wouldn't be sufficient for my intended uses of lazy
>importing, where I need the import to be triggered by
>accessing a specific attribute of a *different* module
>(namely a package which imports classes from submodules
>and puts their names in its own namespace).
Yes, that's a different use case - as I said, other people have
different use cases for lazy importing and wrote libraries with
different approaches. That's why a PEP should be done, to draw those
folks out of the woodwork.
More information about the Python-3000
mailing list