Skip to content

Commit 797acb3

Browse files
committed
DEP: deprecate the mypy plugin
1 parent 081c6dc commit 797acb3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

numpy/typing/mypy_plugin.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Without the plugin the type will default to `ctypes.c_int64`.
1717
1818
.. versionadded:: 1.22
19+
.. deprecated:: 2.3
1920
2021
Examples
2122
--------
@@ -35,7 +36,7 @@
3536

3637
import numpy as np
3738

38-
__all__ = ()
39+
__all__: list[str] = []
3940

4041

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

114-
115115
_HookFunc: TypeAlias = Callable[[AnalyzeTypeContext], mypy.types.Type]
116116

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

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

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

@@ -186,9 +183,15 @@ def get_additional_deps(
186183
)
187184
return [(PRI_MED, fullname, -1)]
188185

189-
190186
def plugin(version: str) -> type:
191-
"""An entry-point for mypy."""
187+
import warnings
188+
189+
warnings.warn(
190+
"`numpy.typing.mypy_plugin` is deprecated, and will be removed in "
191+
"a future release.",
192+
category=DeprecationWarning,
193+
stacklevel=3,
194+
)
192195
return _NumpyPlugin
193196

194197
except ModuleNotFoundError as e:

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ filterwarnings =
2525
# Ignore DeprecationWarnings from distutils
2626
ignore::DeprecationWarning:.*distutils
2727
ignore:\n\n `numpy.distutils`:DeprecationWarning
28+
# Ignore DeprecationWarning from typing.mypy_plugin
29+
ignore:`numpy.typing.mypy_plugin` is deprecated:DeprecationWarning

0 commit comments

Comments
 (0)