diff options
author | Bas van Beek <b.f.van.beek@vu.nl> | 2021-04-14 23:11:09 +0200 |
---|---|---|
committer | Bas van Beek <b.f.van.beek@vu.nl> | 2021-04-14 23:11:09 +0200 |
commit | 7afccd97397a6f102b83ae4c0e0f77e0fbde435c (patch) | |
tree | ada8d613a51a8ce165934604473e4d48b1085a04 | |
parent | 92549ce03ecff346f4b10b181dcfa93ca1c22b3f (diff) | |
download | numpy-7afccd97397a6f102b83ae4c0e0f77e0fbde435c.tar.gz |
MAINT: Relax the integer-type-constraint of `npt._ShapeLike`
Change `int` into the more forgiving `SupportsIndex` protocol
-rw-r--r-- | numpy/typing/_shape.py | 11 | ||||
-rw-r--r-- | numpy/typing/tests/data/pass/array_constructors.py | 3 |
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/typing/_shape.py b/numpy/typing/_shape.py index 4629046ea..b720c3ffc 100644 --- a/numpy/typing/_shape.py +++ b/numpy/typing/_shape.py @@ -1,6 +1,15 @@ +import sys from typing import Sequence, Tuple, Union +if sys.version_info >= (3, 8): + from typing import SupportsIndex +else: + try: + from typing_extensions import SupportsIndex + except ImportError: + SupportsIndex = NotImplemented + _Shape = Tuple[int, ...] # Anything that can be coerced to a shape tuple -_ShapeLike = Union[int, Sequence[int]] +_ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]] diff --git a/numpy/typing/tests/data/pass/array_constructors.py b/numpy/typing/tests/data/pass/array_constructors.py index 63208f139..722fa4b7e 100644 --- a/numpy/typing/tests/data/pass/array_constructors.py +++ b/numpy/typing/tests/data/pass/array_constructors.py @@ -17,6 +17,9 @@ C = [1] def func(i: int, j: int, **kwargs: Any) -> SubClass: return B +np.ndarray(Index()) +np.ndarray([Index()]) + np.array(1, dtype=float) np.array(1, copy=False) np.array(1, order='F') |