summaryrefslogtreecommitdiff
path: root/numpy/typing/mypy_plugin.py
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-02-02 23:22:13 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2021-02-05 17:55:25 +0100
commit8f0aaf522293f8a72c96bc38773c4cd9f0d552c8 (patch)
tree0bf344585f3d91d4afceb2b2f8bbfcfe549815f3 /numpy/typing/mypy_plugin.py
parent2b7be2005f3d74141f9f8e83be603be0ddbe7046 (diff)
downloadnumpy-8f0aaf522293f8a72c96bc38773c4cd9f0d552c8.tar.gz
STY: Remove the string-encasing of certain annotations
String-encasing is redunant now that we can use `from __future__ import annotations`
Diffstat (limited to 'numpy/typing/mypy_plugin.py')
-rw-r--r--numpy/typing/mypy_plugin.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/numpy/typing/mypy_plugin.py b/numpy/typing/mypy_plugin.py
index bdd5c50f3..813ff16d2 100644
--- a/numpy/typing/mypy_plugin.py
+++ b/numpy/typing/mypy_plugin.py
@@ -1,5 +1,7 @@
"""A module containing `numpy`-specific plugins for mypy."""
+from __future__ import annotations
+
import typing as t
import numpy as np
@@ -39,10 +41,10 @@ def _get_precision_dict() -> t.Dict[str, str]:
#: A dictionary mapping type-aliases in `numpy.typing._nbit` to
#: concrete `numpy.typing.NBitBase` subclasses.
-_PRECISION_DICT = _get_precision_dict()
+_PRECISION_DICT: t.Final = _get_precision_dict()
-def _hook(ctx: "AnalyzeTypeContext") -> "Type":
+def _hook(ctx: AnalyzeTypeContext) -> Type:
"""Replace a type-alias with a concrete ``NBitBase`` subclass."""
typ, _, api = ctx
name = typ.name.split(".")[-1]
@@ -50,7 +52,7 @@ def _hook(ctx: "AnalyzeTypeContext") -> "Type":
return api.named_type(name_new)
-if MYPY_EX is None:
+if t.TYPE_CHECKING or MYPY_EX is None:
class _NumpyPlugin(Plugin):
"""A plugin for assigning platform-specific `numpy.number` precisions."""
@@ -64,6 +66,6 @@ if MYPY_EX is None:
return _NumpyPlugin
else:
- def plugin(version: str) -> t.Type["_NumpyPlugin"]:
+ def plugin(version: str) -> t.Type[_NumpyPlugin]:
"""An entry-point for mypy."""
raise MYPY_EX