# 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 is `types.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 an `ImportError`.

      >>> numpy = LazyImport('numpy')

  No import happens on the above line, until we do something like call an `numpy` method or try to do tab completion or introspection on `numpy` in IPython.

      >>> numpy
      <module 'numpy' will be lazily loaded>

  Now the `LazyImport` will do an actual import, and call the hypot function of the imported module.

      >>> numpy.diff([1969, 2011])
      array([42])

  __init__(x)