summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/typing/__init__.py9
-rw-r--r--numpy/typing/_array_like.py4
2 files changed, 11 insertions, 2 deletions
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py
index bc3442a15..1d377f8c4 100644
--- a/numpy/typing/__init__.py
+++ b/numpy/typing/__init__.py
@@ -3,6 +3,13 @@
Typing (:mod:`numpy.typing`)
============================
+.. warning::
+
+ Some of the types in this module rely on features only present in
+ the standard library in Python 3.8 and greater. If you want to use
+ these types in earlier versions of Python, you should install the
+ typing-extensions_ package.
+
Large parts of the NumPy API have PEP-484-style type annotations. In
addition, the following type aliases are available for users.
@@ -13,6 +20,8 @@ Roughly speaking, ``typing.ArrayLike`` is "objects that can be used as
inputs to ``np.array``" and ``typing.DtypeLike`` is "objects that can
be used as inputs to ``np.dtype``".
+.. _typing-extensions: https://pypi.org/project/typing-extensions/
+
Differences from the runtime NumPy API
--------------------------------------
diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py
index 54a612fb4..b73585cf0 100644
--- a/numpy/typing/_array_like.py
+++ b/numpy/typing/_array_like.py
@@ -1,5 +1,5 @@
import sys
-from typing import Any, overload, Sequence, Tuple, Union
+from typing import Any, overload, Sequence, TYPE_CHECKING, Union
from numpy import ndarray
from ._dtype_like import DtypeLike
@@ -15,7 +15,7 @@ else:
else:
HAVE_PROTOCOL = True
-if HAVE_PROTOCOL:
+if TYPE_CHECKING or HAVE_PROTOCOL:
class _SupportsArray(Protocol):
@overload
def __array__(self, __dtype: DtypeLike = ...) -> ndarray: ...