Skip to content

Commit dc78e30

Browse files
jorenhamseberg
andauthored
DEP: Deprecate numpy.typing.mypy_plugin: The sequel (numpy#28134)
* DEP: Address mypy plugin deprecation suggestions by @seberg in numpy#28129 * DOC: Release note for the deprecated ``numpy.typing.mypy_plugin`` * Update numpy/typing/mypy_plugin.py --------- Co-authored-by: Sebastian Berg <[email protected]>
1 parent 709e40e commit dc78e30

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* The ``numpy.typing.mypy_plugin`` has been deprecated in favor of platform-agnostic
2+
static type inference. Please remove ``numpy.typing.mypy_plugin`` from the ``plugins``
3+
section of your mypy configuration. If this change results in new errors being
4+
reported, kindly open an issue.

numpy/typing/mypy_plugin.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
Without the plugin the type will default to `ctypes.c_int64`.
1717
1818
.. versionadded:: 1.22
19-
.. deprecated:: 2.3
19+
20+
.. deprecated:: 2.3
2021
2122
Examples
2223
--------
@@ -32,7 +33,8 @@
3233
3334
"""
3435

35-
from typing import Final
36+
from collections.abc import Callable, Iterable
37+
from typing import TYPE_CHECKING, Final, TypeAlias, cast
3638

3739
import numpy as np
3840

@@ -101,9 +103,6 @@ def _get_c_intp_name() -> str:
101103

102104

103105
try:
104-
from collections.abc import Callable, Iterable
105-
from typing import TYPE_CHECKING, TypeAlias, cast
106-
107106
if TYPE_CHECKING:
108107
from mypy.typeanal import TypeAnalyser
109108

@@ -112,6 +111,13 @@ def _get_c_intp_name() -> str:
112111
from mypy.nodes import MypyFile, ImportFrom, Statement
113112
from mypy.build import PRI_MED
114113

114+
except ModuleNotFoundError as e:
115+
116+
def plugin(version: str) -> type:
117+
raise e
118+
119+
else:
120+
115121
_HookFunc: TypeAlias = Callable[[AnalyzeTypeContext], mypy.types.Type]
116122

117123
def _hook(ctx: AnalyzeTypeContext) -> mypy.types.Type:
@@ -186,15 +192,13 @@ def get_additional_deps(
186192
def plugin(version: str) -> type:
187193
import warnings
188194

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,
195+
plugin = "numpy.typing.mypy_plugin"
196+
# Deprecated 2025-01-10, NumPy 2.3
197+
warn_msg = (
198+
f"`{plugin}` is deprecated, and will be removed in a future "
199+
f"release. Please remove `plugins = {plugin}` in your mypy config."
200+
f"(deprecated in NumPy 2.3)"
194201
)
195-
return _NumpyPlugin
196-
197-
except ModuleNotFoundError as e:
202+
warnings.warn(warn_msg, DeprecationWarning, stacklevel=3)
198203

199-
def plugin(version: str) -> type:
200-
raise e
204+
return _NumpyPlugin

0 commit comments

Comments
 (0)