summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2022-01-24 17:28:33 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2022-01-24 17:29:37 +0100
commit03dc8bfbc809b43b91b4ecb8f481be1ce2644d66 (patch)
treeb9f69cdb9da160293a6d1fc095e13a8a4e22296e /numpy
parent3fbe9852265220c77d8808210539b736be75c8c1 (diff)
downloadnumpy-03dc8bfbc809b43b91b4ecb8f481be1ce2644d66.tar.gz
MAINT: Create the `_ArrayLike` type-alias in `numpy.typing`
Represents a subset of `npt.ArrayLike` that can be parametrized w.r.t. `np.generic`
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/multiarray.pyi5
-rw-r--r--numpy/core/numeric.pyi5
-rw-r--r--numpy/core/shape_base.pyi6
-rw-r--r--numpy/ctypeslib.pyi7
-rw-r--r--numpy/fft/helper.pyi7
-rw-r--r--numpy/lib/arraypad.pyi7
-rw-r--r--numpy/lib/arraysetops.pyi6
-rw-r--r--numpy/lib/function_base.pyi5
-rw-r--r--numpy/lib/shape_base.pyi18
-rw-r--r--numpy/lib/stride_tricks.pyi6
-rw-r--r--numpy/lib/twodim_base.pyi7
-rw-r--r--numpy/lib/type_check.pyi5
-rw-r--r--numpy/typing/_array_like.py6
13 files changed, 28 insertions, 62 deletions
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
index 21af904b9..5e924c2f4 100644
--- a/numpy/core/multiarray.pyi
+++ b/numpy/core/multiarray.pyi
@@ -58,10 +58,9 @@ from numpy.typing import (
# Arrays
NDArray,
ArrayLike,
- _SupportsArray,
+ _ArrayLike,
_SupportsArrayFunc,
_NestedSequence,
- _FiniteNestedSequence,
_ArrayLikeBool_co,
_ArrayLikeUInt_co,
_ArrayLikeInt_co,
@@ -81,8 +80,6 @@ from numpy.typing import (
_SCT = TypeVar("_SCT", bound=generic)
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
# Valid time units
_UnitKind = L[
"Y",
diff --git a/numpy/core/numeric.pyi b/numpy/core/numeric.pyi
index 367a2bff8..796f30304 100644
--- a/numpy/core/numeric.pyi
+++ b/numpy/core/numeric.pyi
@@ -12,7 +12,6 @@ from typing_extensions import TypeGuard
from numpy import (
ComplexWarning as ComplexWarning,
- dtype,
generic,
unsignedinteger,
signedinteger,
@@ -34,8 +33,7 @@ from numpy.typing import (
DTypeLike,
_ShapeLike,
_DTypeLike,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike,
_SupportsArrayFunc,
_ScalarLike_co,
_ArrayLikeBool_co,
@@ -51,7 +49,6 @@ _T = TypeVar("_T")
_SCT = TypeVar("_SCT", bound=generic)
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
_CorrelateMode = Literal["valid", "same", "full"]
__all__: list[str]
diff --git a/numpy/core/shape_base.pyi b/numpy/core/shape_base.pyi
index 63cbd773c..e2cf26075 100644
--- a/numpy/core/shape_base.pyi
+++ b/numpy/core/shape_base.pyi
@@ -1,14 +1,12 @@
from collections.abc import Sequence
from typing import TypeVar, overload, Any, SupportsIndex
-from numpy import generic, dtype
-from numpy.typing import ArrayLike, NDArray, _FiniteNestedSequence, _SupportsArray
+from numpy import generic
+from numpy.typing import ArrayLike, NDArray, _ArrayLike
_SCT = TypeVar("_SCT", bound=generic)
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
__all__: list[str]
@overload
diff --git a/numpy/ctypeslib.pyi b/numpy/ctypeslib.pyi
index 5b48e6bc0..6eb8d71a0 100644
--- a/numpy/ctypeslib.pyi
+++ b/numpy/ctypeslib.pyi
@@ -33,7 +33,6 @@ from numpy import (
ulonglong,
single,
double,
- float_,
longdouble,
void,
)
@@ -41,10 +40,8 @@ from numpy.core._internal import _ctypes
from numpy.core.multiarray import flagsobj
from numpy.typing import (
# Arrays
- ArrayLike,
NDArray,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike,
# Shapes
_ShapeLike,
@@ -74,8 +71,6 @@ _DType = TypeVar("_DType", bound=dtype[Any])
_DTypeOptional = TypeVar("_DTypeOptional", bound=None | dtype[Any])
_SCT = TypeVar("_SCT", bound=generic)
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
_FlagsKind = L[
'C_CONTIGUOUS', 'CONTIGUOUS', 'C',
'F_CONTIGUOUS', 'FORTRAN', 'F',
diff --git a/numpy/fft/helper.pyi b/numpy/fft/helper.pyi
index a7f3bdf51..5a1565858 100644
--- a/numpy/fft/helper.pyi
+++ b/numpy/fft/helper.pyi
@@ -1,20 +1,17 @@
from typing import Any, TypeVar, overload
-from numpy import generic, dtype, integer, floating, complexfloating
+from numpy import generic, integer, floating, complexfloating
from numpy.typing import (
NDArray,
ArrayLike,
_ShapeLike,
- _SupportsArray,
- _FiniteNestedSequence,
+ _ArrayLike,
_ArrayLikeFloat_co,
_ArrayLikeComplex_co,
)
_SCT = TypeVar("_SCT", bound=generic)
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
__all__: list[str]
@overload
diff --git a/numpy/lib/arraypad.pyi b/numpy/lib/arraypad.pyi
index 1f74f2506..d88224dd2 100644
--- a/numpy/lib/arraypad.pyi
+++ b/numpy/lib/arraypad.pyi
@@ -6,14 +6,13 @@ from typing import (
Protocol,
)
-from numpy import ndarray, dtype, generic
+from numpy import generic
from numpy.typing import (
ArrayLike,
NDArray,
_ArrayLikeInt,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike,
)
_SCT = TypeVar("_SCT", bound=generic)
@@ -42,8 +41,6 @@ _ModeKind = L[
"empty",
]
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
__all__: list[str]
# TODO: In practice each keyword argument is exclusive to one or more
diff --git a/numpy/lib/arraysetops.pyi b/numpy/lib/arraysetops.pyi
index e7e230bf1..c3c759d5b 100644
--- a/numpy/lib/arraysetops.pyi
+++ b/numpy/lib/arraysetops.pyi
@@ -7,7 +7,6 @@ from typing import (
)
from numpy import (
- dtype,
generic,
number,
bool_,
@@ -41,8 +40,7 @@ from numpy import (
from numpy.typing import (
ArrayLike,
NDArray,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike,
_ArrayLikeBool_co,
_ArrayLikeDT64_co,
_ArrayLikeTD64_co,
@@ -87,8 +85,6 @@ _SCTNoCast = TypeVar(
void,
)
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
__all__: list[str]
@overload
diff --git a/numpy/lib/function_base.pyi b/numpy/lib/function_base.pyi
index d99672169..bba4c0297 100644
--- a/numpy/lib/function_base.pyi
+++ b/numpy/lib/function_base.pyi
@@ -18,7 +18,6 @@ else:
from numpy import (
vectorize as vectorize,
ufunc,
- dtype,
generic,
floating,
complexfloating,
@@ -38,8 +37,7 @@ from numpy.typing import (
_ShapeLike,
_ScalarLike_co,
_DTypeLike,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike,
_ArrayLikeInt_co,
_ArrayLikeFloat_co,
_ArrayLikeComplex_co,
@@ -67,7 +65,6 @@ _SCT = TypeVar("_SCT", bound=generic)
_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
_2Tuple = tuple[_T, _T]
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
class _TrimZerosSequence(Protocol[_T_co]):
def __len__(self) -> int: ...
diff --git a/numpy/lib/shape_base.pyi b/numpy/lib/shape_base.pyi
index 82702e67c..4c81462bb 100644
--- a/numpy/lib/shape_base.pyi
+++ b/numpy/lib/shape_base.pyi
@@ -4,7 +4,6 @@ from typing import TypeVar, Any, overload, SupportsIndex, Protocol
from numpy import (
generic,
integer,
- dtype,
ufunc,
bool_,
unsignedinteger,
@@ -18,22 +17,19 @@ from numpy.typing import (
ArrayLike,
NDArray,
_ShapeLike,
- _FiniteNestedSequence,
- _SupportsArray,
- _ArrayLikeBool_co,
- _ArrayLikeUInt_co,
- _ArrayLikeInt_co,
- _ArrayLikeFloat_co,
- _ArrayLikeComplex_co,
- _ArrayLikeObject_co,
+ _ArrayLike,
+ _ArrayLikeBool_co,
+ _ArrayLikeUInt_co,
+ _ArrayLikeInt_co,
+ _ArrayLikeFloat_co,
+ _ArrayLikeComplex_co,
+ _ArrayLikeObject_co,
)
from numpy.core.shape_base import vstack
_SCT = TypeVar("_SCT", bound=generic)
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
# The signatures of `__array_wrap__` and `__array_prepare__` are the same;
# give them unique names for the sake of clarity
class _ArrayWrap(Protocol):
diff --git a/numpy/lib/stride_tricks.pyi b/numpy/lib/stride_tricks.pyi
index e05a9f74c..84dcd12e7 100644
--- a/numpy/lib/stride_tricks.pyi
+++ b/numpy/lib/stride_tricks.pyi
@@ -1,18 +1,16 @@
from collections.abc import Iterable
from typing import Any, TypeVar, overload, SupportsIndex
-from numpy import dtype, generic
+from numpy import generic
from numpy.typing import (
NDArray,
ArrayLike,
_ShapeLike,
_Shape,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike
)
_SCT = TypeVar("_SCT", bound=generic)
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
__all__: list[str]
diff --git a/numpy/lib/twodim_base.pyi b/numpy/lib/twodim_base.pyi
index 1ac510ac2..b08cf8383 100644
--- a/numpy/lib/twodim_base.pyi
+++ b/numpy/lib/twodim_base.pyi
@@ -7,8 +7,6 @@ from typing import (
)
from numpy import (
- ndarray,
- dtype,
generic,
number,
bool_,
@@ -28,9 +26,8 @@ from numpy.typing import (
DTypeLike,
_DTypeLike,
ArrayLike,
+ _ArrayLike,
NDArray,
- _FiniteNestedSequence,
- _SupportsArray,
_SupportsArrayFunc,
_ArrayLikeInt_co,
_ArrayLikeFloat_co,
@@ -47,8 +44,6 @@ _MaskFunc = Callable[
NDArray[Union[number[Any], bool_, timedelta64, datetime64, object_]],
]
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
__all__: list[str]
@overload
diff --git a/numpy/lib/type_check.pyi b/numpy/lib/type_check.pyi
index 72eb777be..0d8eeb1bd 100644
--- a/numpy/lib/type_check.pyi
+++ b/numpy/lib/type_check.pyi
@@ -25,8 +25,7 @@ from numpy.typing import (
_64Bit,
_SupportsDType,
_ScalarLike_co,
- _FiniteNestedSequence,
- _SupportsArray,
+ _ArrayLike,
_DTypeLikeComplex,
)
@@ -36,8 +35,6 @@ _SCT = TypeVar("_SCT", bound=generic)
_NBit1 = TypeVar("_NBit1", bound=NBitBase)
_NBit2 = TypeVar("_NBit2", bound=NBitBase)
-_ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]]
-
class _SupportsReal(Protocol[_T_co]):
@property
def real(self) -> _T_co: ...
diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py
index ea9ade295..02f264222 100644
--- a/numpy/typing/_array_like.py
+++ b/numpy/typing/_array_like.py
@@ -57,6 +57,12 @@ _FiniteNestedSequence = Union[
Sequence[Sequence[Sequence[Sequence[_T]]]],
]
+# A subset of `npt.ArrayLike` that can be parametrized w.r.t. `np.generic`
+_ArrayLike = Union[
+ _SupportsArray["dtype[_ScalarType]"],
+ _NestedSequence[_SupportsArray["dtype[_ScalarType]"]],
+]
+
# A union representing array-like objects; consists of two typevars:
# One representing types that can be parametrized w.r.t. `np.dtype`
# and another one for the rest