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
Constant MYPY​_EX Undocumented
Class _​Numpy​Plugin 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.
Function plugin An entry-point for mypy.
Constant ​_C​_INTP Undocumented
Constant ​_EXTENDED​_PRECISION​_LIST Undocumented
Constant ​_PRECISION​_DICT Undocumented
Variable _​Hook​Func Undocumented
MYPY_EX =

Undocumented

Value
ex
def _get_c_intp_name():

Undocumented

Returns
strUndocumented
def _get_extended_precision_list():

Undocumented

Returns
list[str]Undocumented
def _get_precision_dict():

Undocumented

Returns
dict[str, str]Undocumented
def _hook(ctx):
Replace a type-alias with a concrete NBitBase subclass.
Parameters
ctx:AnalyzeTypeContextUndocumented
Returns
TypeUndocumented
def _index(iterable, id):
Identify the first ImportFrom instance the specified id.
Parameters
iterable:Iterable[Statement]Undocumented
id:strUndocumented
Returns
intUndocumented
def _override_imports(file, module, imports):
Override the first module-based import with new imports.
Parameters
file:MypyFileUndocumented
module:strUndocumented
imports:list[tuple[str, None|str]]Undocumented
def plugin(version):
An entry-point for mypy.
Parameters
version:strUndocumented
Returns
type[_NumpyPlugin]Undocumented
_C_INTP =

Undocumented

Value
_get_c_intp_name()
_EXTENDED_PRECISION_LIST =

Undocumented

Value
_get_extended_precision_list()
_PRECISION_DICT =

Undocumented

Value
_get_precision_dict()
_HookFunc =

Undocumented