diff options
author | Josh Wilson <person142@users.noreply.github.com> | 2020-06-11 08:42:55 -0700 |
---|---|---|
committer | Josh Wilson <person142@users.noreply.github.com> | 2020-06-11 08:42:55 -0700 |
commit | 4a120f0d073506329b564bfe9e69db2f6b612964 (patch) | |
tree | 8a1a728191d074dfd636c60a4b363969585e5a77 /numpy | |
parent | 70130f848b7c526862fa6ff9667f078a628d86a1 (diff) | |
download | numpy-4a120f0d073506329b564bfe9e69db2f6b612964.tar.gz |
DOC: add warning about typing-extensions module to numpy.typing docs
Typing `ArrayLike` correctly relies on `Protocol`, so warn users that
they should be on 3.8+ or install `typing-extensions` if they want
everything to work as expected.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/typing/__init__.py | 9 | ||||
-rw-r--r-- | numpy/typing/_array_like.py | 4 |
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: ... |