diff options
author | Qiyu8 <fangchunlin@huawei.com> | 2020-12-14 16:35:01 +0800 |
---|---|---|
committer | Qiyu8 <fangchunlin@huawei.com> | 2020-12-14 16:35:01 +0800 |
commit | 4c7b3d64780c0cdfb8279c978d8b5a411995aee4 (patch) | |
tree | 4f98ed596916b9e8f5404939d7a39b86b6da52e6 /numpy/typing/_array_like.py | |
parent | 30c01122d2631269fa28f057f6723168b64ca783 (diff) | |
parent | e3722cea8adb7b66084a7edbc6afb978c5521c16 (diff) | |
download | numpy-4c7b3d64780c0cdfb8279c978d8b5a411995aee4.tar.gz |
Merge branch 'master' of github.com:numpy/numpy into einsum-dot
Diffstat (limited to 'numpy/typing/_array_like.py')
-rw-r--r-- | numpy/typing/_array_like.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py index a1a604239..63b67b33a 100644 --- a/numpy/typing/_array_like.py +++ b/numpy/typing/_array_like.py @@ -1,7 +1,9 @@ +from __future__ import annotations + import sys -from typing import Any, overload, Sequence, TYPE_CHECKING, Union +from typing import Any, overload, Sequence, TYPE_CHECKING, Union, TypeVar -from numpy import ndarray +from numpy import ndarray, dtype from ._scalars import _ScalarLike from ._dtype_like import DTypeLike @@ -16,12 +18,15 @@ else: else: HAVE_PROTOCOL = True +_DType = TypeVar("_DType", bound="dtype[Any]") + if TYPE_CHECKING or HAVE_PROTOCOL: - class _SupportsArray(Protocol): - @overload - def __array__(self, __dtype: DTypeLike = ...) -> ndarray: ... - @overload - def __array__(self, dtype: DTypeLike = ...) -> ndarray: ... + # The `_SupportsArray` protocol only cares about the default dtype + # (i.e. `dtype=None`) of the to-be returned array. + # Concrete implementations of the protocol are responsible for adding + # any and all remaining overloads + class _SupportsArray(Protocol[_DType]): + def __array__(self, dtype: None = ...) -> ndarray[Any, _DType]: ... else: _SupportsArray = Any @@ -36,5 +41,5 @@ ArrayLike = Union[ _ScalarLike, Sequence[_ScalarLike], Sequence[Sequence[Any]], # TODO: Wait for support for recursive types - _SupportsArray, + "_SupportsArray[Any]", ] |