module documentation
(source)

Utilities for mypy.stubgen, mypy.stubgenc, and mypy.stubdoc modules.
Class ​Cant​Import Undocumented
Function common​_dir​_prefix Undocumented
Function default​_py2​_interpreter Find a system Python 2 interpreter.
Function fail​_missing Undocumented
Function find​_module​_path​_and​_all​_py2 Return tuple (module path, module __all__) for a Python 2 module.
Function find​_module​_path​_and​_all​_py3 Find module and determine __all__ for a Python 3 module.
Function find​_module​_path​_using​_py2​_sys​_path Try to find the path of a .py file for a module using Python 2 sys.path.
Function find​_module​_path​_using​_sys​_path Undocumented
Function generate​_guarded Ignore or report errors during stub generation.
Function remove​_misplaced​_type​_comments Remove comments from source that could be understood as misplaced type comments.
Function report​_missing Undocumented
Function walk​_packages Iterates through all packages and sub-packages in the given list.
Constant NOT​_IMPORTABLE​_MODULES Undocumented
Constant PY2​_MODULES Undocumented
def common_dir_prefix(paths): (source)

Undocumented

Parameters
paths:List[str]Undocumented
Returns
strUndocumented
def default_py2_interpreter(): (source)

Find a system Python 2 interpreter.

Return full path or exit if failed.

Returns
strUndocumented
def fail_missing(mod, reason): (source)

Undocumented

Parameters
mod:strUndocumented
reason:ModuleNotFoundReasonUndocumented
def find_module_path_and_all_py2(module, interpreter): (source)

Return tuple (module path, module __all__) for a Python 2 module.

The path refers to the .py/.py[co] file. The second tuple item is None if the module doesn't define __all__.

Raise CantImport if the module can't be imported, or exit if it's a C extension module.

Parameters
module:strUndocumented
interpreter:strUndocumented
Returns
Optional[Tuple[Optional[str], Optional[List[str]]]]Undocumented
def find_module_path_and_all_py3(inspect, module, verbose): (source)

Find module and determine __all__ for a Python 3 module.

Return None if the module is a C module. Return (module_path, __all__) if it is a Python module. Raise CantImport if import failed.

Parameters
inspect:ModuleInspectUndocumented
module:strUndocumented
verbose:boolUndocumented
Returns
Optional[Tuple[Optional[str], Optional[List[str]]]]Undocumented
def find_module_path_using_py2_sys_path(module, interpreter): (source)

Try to find the path of a .py file for a module using Python 2 sys.path.

Return None if no match was found.

Parameters
module:strUndocumented
interpreter:strUndocumented
Returns
Optional[str]Undocumented
def find_module_path_using_sys_path(module, sys_path): (source)

Undocumented

Parameters
module:strUndocumented
sys​_path:List[str]Undocumented
Returns
Optional[str]Undocumented
@contextmanager
def generate_guarded(mod, target, ignore_errors=True, verbose=False): (source)

Ignore or report errors during stub generation.

Optionally report success.

Parameters
mod:strUndocumented
target:strUndocumented
ignore​_errors:boolUndocumented
verbose:boolUndocumented
Returns
Iterator[None]Undocumented
def remove_misplaced_type_comments(source): (source)

Remove comments from source that could be understood as misplaced type comments.

Normal comments may look like misplaced type comments, and since they cause blocking parse errors, we want to avoid them.

Parameters
source:Union[str, bytes]Undocumented
Returns
Union[str, bytes]Undocumented
def report_missing(mod, message='', traceback=''): (source)

Undocumented

Parameters
mod:strUndocumented
message:Optional[str]Undocumented
traceback:strUndocumented
def walk_packages(inspect, packages, verbose=False): (source)

Iterates through all packages and sub-packages in the given list.

This uses runtime imports (in another process) to find both Python and C modules. For Python packages we simply pass the __path__ attribute to pkgutil.walk_packages() to get the content of the package (all subpackages and modules). However, packages in C extensions do not have this attribute, so we have to roll out our own logic: recursively find all modules imported in the package that have matching names.

Parameters
inspect:ModuleInspectUndocumented
packages:List[str]Undocumented
verbose:boolUndocumented
Returns
Iterator[str]Undocumented
NOT_IMPORTABLE_MODULES: tuple = (source)

Undocumented

Value
()
PY2_MODULES: set[str] = (source)

Undocumented

Value
set(['cStringIO', 'urlparse', 'collections.UserDict'])