lazyimports¶
Module: lazyimports
¶
Inheritance diagram for nitime.lazyimports
:
This module provides lazy import functionality to improve the import performance of nitime. For example, some parts of nitime leverage and import matplotlib, which is quite a big package, yet most of the nitime code does not depend on matplotlib. By lazily-loading a module, we defer the overhead of importing it until the first time it is actually used, thereby speeding up nitime imports.
A generic LazyImport
class is implemented which takes the module name
as a parameter, and acts as a proxy for that module, importing it only when
the module is used, but effectively acting as the module in every other way
(including inside IPython with respect to introspection and tab completion)
with the exception of reload() - reloading a LazyImport
raises an
ImportError
.
Commonly used nitime lazy imports are also defined in nitime.lazy
, so
they can be reused throughout nitime.
LazyImport
¶
-
class
nitime.lazyimports.
LazyImport
(x)¶ Bases:
object
WARNING: To get Sphinx documentation to build we disable LazyImports, which makes Sphinx incorrectly report this class as having a base class of object. In reality,LazyImport
’s base class istypes.ModuleType
.This class takes the module name as a parameter, and acts as a proxy for that module, importing it only when the module is used, but effectively acting as the module in every other way (including inside IPython with respect to introspection and tab completion) with the exception of reload()- reloading a
LazyImport
raises anImportError
.>>> mlab = LazyImport('matplotlib.mlab')
No import happens on the above line, until we do something like call an
mlab
method or try to do tab completion or introspection onmlab
in IPython.>>> mlab <module 'matplotlib.mlab' will be lazily loaded>
Now the
LazyImport
will do an actual import, and call the dist function of the imported module.>>> mlab.dist(1969,2011) 42.0
-
__init__
(x)¶ Initialize self. See help(type(self)) for accurate signature.
-