summaryrefslogtreecommitdiff
path: root/numpy/typing/_array_like.py
blob: 54a612fb449c8a43d96f157939d978bc16cd89cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys
from typing import Any, overload, Sequence, Tuple, Union

from numpy import ndarray
from ._dtype_like import DtypeLike

if sys.version_info >= (3, 8):
    from typing import Protocol
    HAVE_PROTOCOL = True
else:
    try:
        from typing_extensions import Protocol
    except ImportError:
        HAVE_PROTOCOL = False
    else:
        HAVE_PROTOCOL = True

if HAVE_PROTOCOL:
    class _SupportsArray(Protocol):
        @overload
        def __array__(self, __dtype: DtypeLike = ...) -> ndarray: ...
        @overload
        def __array__(self, dtype: DtypeLike = ...) -> ndarray: ...
else:
    _SupportsArray = Any

ArrayLike = Union[bool, int, float, complex, _SupportsArray, Sequence]