_modules module

exception pyflyby._modules.ErrorDuringImportError

Exception raised by import_module if the module exists but an exception occurred while attempting to import it. That nested exception could be ImportError, e.g. if a module tries to import another module that doesn’t exist.

class pyflyby._modules.ModuleHandle(arg)

A handle to a module.

_cls_cache: Dict[Any, Any] = {}
classmethod _from_filename(filename)
classmethod _from_module(module)
classmethod _from_modulename(modulename)
static _member_from_node(node)
property ancestors
property block
classmethod containing(identifier)

Try to find the module that defines a name such as a.b.c by trying to import a, a.b, and a.b.c.

Returns:

The name of the ‘deepest’ module (most commonly it would be a.b in this example).

Return type:

Module

property exists

Return whether the module exists, according to pkgutil. Note that this doesn’t work for things that are only known by using sys.meta_path.

property exports

Get symbols exported by this module.

Note that this will not recognize symbols that are dynamically introduced to the module’s namespace or __all__ list.

Return type:

ImportSet or None

Returns:

Exports, or None if nothing exported.

property filename

Return the filename, if appropriate.

The module itself will not be imported, but if the module is not a top-level module/package, accessing this attribute may cause the parent package to be imported.

Return type:

Filename

static list()

Enumerate all top-level packages/modules.

Return type:

tuple of ModuleHandle s

property module

Return the module instance.

Return type:

types.ModuleType

Raises:
  • ErrorDuringImportError – The module should exist but an error occurred while attempting to import it.

  • ImportError – The module doesn’t exist.

name: DottedIdentifier
property parent
property submodules

Enumerate the importable submodules of this module.

>>> ModuleHandle("email").submodules      
(..., ModuleHandle('email.encoders'), ..., ModuleHandle('email.mime'), ...)
Return type:

tuple of ModuleHandle s

property text
pyflyby._modules._my_iter_modules(path, prefix='')
pyflyby._modules.import_module(module_name)
pyflyby._modules.pyc_to_py(filename)