module documentation

A mypy plugin for managing a number of platform-specific annotations. Its functionality can be split into three distinct parts:

  • Assigning the (platform-dependent) precisions of certain ~numpy.number subclasses, including the likes of ~numpy.int_, ~numpy.intp and ~numpy.longlong. See the documentation on :ref:`scalar types <arrays.scalars.built-in>` for a comprehensive overview of the affected classes. Without the plugin the precision of all relevant classes will be inferred as ~typing.Any.

  • Removing all extended-precision ~numpy.number subclasses that are unavailable for the platform in question. Most notably this includes the likes of ~numpy.float128 and ~numpy.complex256. Without the plugin all extended-precision types will, as far as mypy is concerned, be available to all platforms.

  • Assigning the (platform-dependent) precision of ~numpy.ctypeslib.c_intp. Without the plugin the type will default to ctypes.c_int64.

    New in version 1.22.

Examples

To enable the plugin, one must add it to their mypy configuration file:

[mypy]
plugins = numpy.typing.mypy_plugin
Function plugin An entry-point for mypy.
Constant MYPY_EX Undocumented
Class _NumpyPlugin A mypy plugin for handling versus numpy-specific typing tasks.
Function _get_c_intp_name Undocumented
Function _get_extended_precision_list Undocumented
Function _get_precision_dict Undocumented
Function _hook Replace a type-alias with a concrete NBitBase subclass.
Function _index Identify the first ImportFrom instance the specified id.
Function _override_imports Override the first module-based import with new imports.
Constant _C_INTP Undocumented
Constant _EXTENDED_PRECISION_LIST Undocumented
Constant _PRECISION_DICT Undocumented
Type Alias _HookFunc Undocumented
def plugin(version: str) -> type[_NumpyPlugin]: (source)

An entry-point for mypy.

Undocumented

Value
None
def _get_c_intp_name() -> str: (source)

Undocumented

def _get_extended_precision_list() -> list[str]: (source)

Undocumented

def _get_precision_dict() -> dict[str, str]: (source)

Undocumented

Replace a type-alias with a concrete NBitBase subclass.

def _index(iterable: Iterable[Statement], id: str) -> int: (source)

Identify the first ImportFrom instance the specified id.

def _override_imports(file: MypyFile, module: str, imports: list[tuple[str, None|str]]): (source)

Override the first module-based import with new imports.

Undocumented

Value
_get_c_intp_name()
_EXTENDED_PRECISION_LIST = (source)

Undocumented

Value
_get_extended_precision_list()
_PRECISION_DICT = (source)

Undocumented

Value
_get_precision_dict()
_HookFunc = (source)

Undocumented

Value
Callable[[AnalyzeTypeContext], Type]