Skip to content

Commit

Permalink
DEP: deprecate the mypy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham committed Jan 9, 2025
1 parent 081c6dc commit 797acb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions numpy/typing/mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Without the plugin the type will default to `ctypes.c_int64`.
.. versionadded:: 1.22
.. deprecated:: 2.3
Examples
--------
Expand All @@ -35,7 +36,7 @@

import numpy as np

__all__ = ()
__all__: list[str] = []


def _get_precision_dict() -> dict[str, str]:
Expand Down Expand Up @@ -111,18 +112,15 @@ def _get_c_intp_name() -> str:
from mypy.nodes import MypyFile, ImportFrom, Statement
from mypy.build import PRI_MED


_HookFunc: TypeAlias = Callable[[AnalyzeTypeContext], mypy.types.Type]


def _hook(ctx: AnalyzeTypeContext) -> mypy.types.Type:
"""Replace a type-alias with a concrete ``NBitBase`` subclass."""
typ, _, api = ctx
name = typ.name.split(".")[-1]
name_new = _PRECISION_DICT[f"{_MODULE}._nbit.{name}"]
return cast("TypeAnalyser", api).named_type(name_new)


def _index(iterable: Iterable[Statement], id: str) -> int:
"""Identify the first ``ImportFrom`` instance the specified `id`."""
for i, value in enumerate(iterable):
Expand All @@ -146,7 +144,6 @@ def _override_imports(
i = _index(lst, module)
lst[i] = import_obj


class _NumpyPlugin(Plugin):
"""A mypy plugin for handling versus numpy-specific typing tasks."""

Expand Down Expand Up @@ -186,9 +183,15 @@ def get_additional_deps(
)
return [(PRI_MED, fullname, -1)]


def plugin(version: str) -> type:
"""An entry-point for mypy."""
import warnings

warnings.warn(
"`numpy.typing.mypy_plugin` is deprecated, and will be removed in "
"a future release.",
category=DeprecationWarning,
stacklevel=3,
)
return _NumpyPlugin

except ModuleNotFoundError as e:
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ filterwarnings =
# Ignore DeprecationWarnings from distutils
ignore::DeprecationWarning:.*distutils
ignore:\n\n `numpy.distutils`:DeprecationWarning
# Ignore DeprecationWarning from typing.mypy_plugin
ignore:`numpy.typing.mypy_plugin` is deprecated:DeprecationWarning

0 comments on commit 797acb3

Please sign in to comment.