diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/__init__.pyi | 7 | ||||
| -rw-r--r-- | numpy/core/function_base.pyi | 14 | ||||
| -rw-r--r-- | numpy/core/multiarray.pyi | 10 | ||||
| -rw-r--r-- | numpy/core/numeric.pyi | 8 | ||||
| -rw-r--r-- | numpy/core/numerictypes.pyi | 9 | ||||
| -rw-r--r-- | numpy/ctypeslib.pyi | 7 | ||||
| -rw-r--r-- | numpy/lib/function_base.pyi | 8 | ||||
| -rw-r--r-- | numpy/lib/npyio.pyi | 9 | ||||
| -rw-r--r-- | numpy/lib/twodim_base.pyi | 7 | ||||
| -rw-r--r-- | numpy/typing/__init__.py | 1 | ||||
| -rw-r--r-- | numpy/typing/_dtype_like.py | 13 |
11 files changed, 23 insertions, 70 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 92f98a801..062df938d 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -38,6 +38,7 @@ from numpy.typing import ( # DTypes DTypeLike, + _DTypeLike, _SupportsDType, _VoidDTypeLike, @@ -1411,12 +1412,6 @@ _T_contra = TypeVar("_T_contra", contravariant=True) _2Tuple = tuple[_T, _T] _CastingKind = L["no", "equiv", "safe", "same_kind", "unsafe"] -_DTypeLike = Union[ - dtype[_ScalarType], - type[_ScalarType], - _SupportsDType[dtype[_ScalarType]], -] - _ArrayUInt_co = NDArray[Union[bool_, unsignedinteger[Any]]] _ArrayInt_co = NDArray[Union[bool_, integer[Any]]] _ArrayFloat_co = NDArray[Union[bool_, integer[Any], floating[Any]]] diff --git a/numpy/core/function_base.pyi b/numpy/core/function_base.pyi index b21892177..520046c19 100644 --- a/numpy/core/function_base.pyi +++ b/numpy/core/function_base.pyi @@ -1,32 +1,22 @@ from typing import ( Literal as L, overload, - Union, Any, SupportsIndex, TypeVar, ) -from numpy import floating, complexfloating, generic, dtype +from numpy import floating, complexfloating, generic from numpy.typing import ( NDArray, - ArrayLike, DTypeLike, - _SupportsDType, - _SupportsArray, - _NumberLike_co, + _DTypeLike, _ArrayLikeFloat_co, _ArrayLikeComplex_co, ) _SCT = TypeVar("_SCT", bound=generic) -_DTypeLike = Union[ - dtype[_SCT], - type[_SCT], - _SupportsDType[dtype[_SCT]], -] - __all__: list[str] @overload diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi index f2d3622d2..21af904b9 100644 --- a/numpy/core/multiarray.pyi +++ b/numpy/core/multiarray.pyi @@ -8,11 +8,9 @@ from typing import ( Any, overload, TypeVar, - Union, SupportsIndex, final, Final, - Protocol, ) from numpy import ( @@ -55,7 +53,7 @@ from numpy.typing import ( # DTypes DTypeLike, - _SupportsDType, + _DTypeLike, # Arrays NDArray, @@ -83,12 +81,6 @@ from numpy.typing import ( _SCT = TypeVar("_SCT", bound=generic) _ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) -# Subscriptable subsets of `npt.DTypeLike` and `npt.ArrayLike` -_DTypeLike = Union[ - dtype[_SCT], - type[_SCT], - _SupportsDType[dtype[_SCT]], -] _ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]] # Valid time units diff --git a/numpy/core/numeric.pyi b/numpy/core/numeric.pyi index d5e28d24c..367a2bff8 100644 --- a/numpy/core/numeric.pyi +++ b/numpy/core/numeric.pyi @@ -1,7 +1,6 @@ from collections.abc import Callable, Sequence from typing import ( Any, - Union, overload, TypeVar, Literal, @@ -34,7 +33,7 @@ from numpy.typing import ( NDArray, DTypeLike, _ShapeLike, - _SupportsDType, + _DTypeLike, _FiniteNestedSequence, _SupportsArray, _SupportsArrayFunc, @@ -52,11 +51,6 @@ _T = TypeVar("_T") _SCT = TypeVar("_SCT", bound=generic) _ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) -_DTypeLike = Union[ - dtype[_SCT], - type[_SCT], - _SupportsDType[dtype[_SCT]], -] _ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]] _CorrelateMode = Literal["valid", "same", "full"] diff --git a/numpy/core/numerictypes.pyi b/numpy/core/numerictypes.pyi index 09c180a0f..eef4fef72 100644 --- a/numpy/core/numerictypes.pyi +++ b/numpy/core/numerictypes.pyi @@ -46,18 +46,11 @@ from numpy.core._type_aliases import ( sctypes as sctypes, ) -from numpy.typing import DTypeLike, ArrayLike, _SupportsDType +from numpy.typing import DTypeLike, ArrayLike, _DTypeLike _T = TypeVar("_T") _SCT = TypeVar("_SCT", bound=generic) -# A paramtrizable subset of `npt.DTypeLike` -_DTypeLike = Union[ - type[_SCT], - dtype[_SCT], - _SupportsDType[dtype[_SCT]], -] - class _CastFunc(Protocol): def __call__( self, x: ArrayLike, k: DTypeLike = ... diff --git a/numpy/ctypeslib.pyi b/numpy/ctypeslib.pyi index 106356873..5b48e6bc0 100644 --- a/numpy/ctypeslib.pyi +++ b/numpy/ctypeslib.pyi @@ -51,7 +51,7 @@ from numpy.typing import ( # DTypes DTypeLike, - _SupportsDType, + _DTypeLike, _VoidDTypeLike, _BoolCodes, _UByteCodes, @@ -74,11 +74,6 @@ _DType = TypeVar("_DType", bound=dtype[Any]) _DTypeOptional = TypeVar("_DTypeOptional", bound=None | dtype[Any]) _SCT = TypeVar("_SCT", bound=generic) -_DTypeLike = Union[ - dtype[_SCT], - type[_SCT], - _SupportsDType[dtype[_SCT]], -] _ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]] _FlagsKind = L[ diff --git a/numpy/lib/function_base.pyi b/numpy/lib/function_base.pyi index 6e2f886cf..d99672169 100644 --- a/numpy/lib/function_base.pyi +++ b/numpy/lib/function_base.pyi @@ -2,7 +2,6 @@ import sys from collections.abc import Sequence, Iterator, Callable, Iterable from typing import ( Literal as L, - Union, Any, TypeVar, overload, @@ -38,7 +37,7 @@ from numpy.typing import ( DTypeLike, _ShapeLike, _ScalarLike_co, - _SupportsDType, + _DTypeLike, _FiniteNestedSequence, _SupportsArray, _ArrayLikeInt_co, @@ -69,11 +68,6 @@ _ArrayType = TypeVar("_ArrayType", bound=NDArray[Any]) _2Tuple = tuple[_T, _T] _ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]] -_DTypeLike = Union[ - dtype[_SCT], - type[_SCT], - _SupportsDType[dtype[_SCT]], -] class _TrimZerosSequence(Protocol[_T_co]): def __len__(self) -> int: ... diff --git a/numpy/lib/npyio.pyi b/numpy/lib/npyio.pyi index 4f11fa807..b96e9dada 100644 --- a/numpy/lib/npyio.pyi +++ b/numpy/lib/npyio.pyi @@ -9,7 +9,6 @@ from typing import ( Any, TypeVar, Generic, - Union, IO, overload, Protocol, @@ -31,7 +30,7 @@ from numpy.typing import ( ArrayLike, DTypeLike, NDArray, - _SupportsDType, + _DTypeLike, _SupportsArrayFunc, ) @@ -47,12 +46,6 @@ _SCT = TypeVar("_SCT", bound=generic) _CharType_co = TypeVar("_CharType_co", str, bytes, covariant=True) _CharType_contra = TypeVar("_CharType_contra", str, bytes, contravariant=True) -_DTypeLike = Union[ - type[_SCT], - dtype[_SCT], - _SupportsDType[dtype[_SCT]], -] - class _SupportsGetItem(Protocol[_T_contra, _T_co]): def __getitem__(self, key: _T_contra, /) -> _T_co: ... diff --git a/numpy/lib/twodim_base.pyi b/numpy/lib/twodim_base.pyi index 491862408..1ac510ac2 100644 --- a/numpy/lib/twodim_base.pyi +++ b/numpy/lib/twodim_base.pyi @@ -26,7 +26,7 @@ from numpy import ( from numpy.typing import ( DTypeLike, - _SupportsDType, + _DTypeLike, ArrayLike, NDArray, _FiniteNestedSequence, @@ -47,11 +47,6 @@ _MaskFunc = Callable[ NDArray[Union[number[Any], bool_, timedelta64, datetime64, object_]], ] -_DTypeLike = Union[ - type[_SCT], - dtype[_SCT], - _SupportsDType[dtype[_SCT]], -] _ArrayLike = _FiniteNestedSequence[_SupportsArray[dtype[_SCT]]] __all__: list[str] diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py index 72ac750ae..acef90ce4 100644 --- a/numpy/typing/__init__.py +++ b/numpy/typing/__init__.py @@ -323,6 +323,7 @@ from ._scalars import ( from ._shape import _Shape, _ShapeLike from ._dtype_like import ( DTypeLike as DTypeLike, + _DTypeLike, _SupportsDType, _VoidDTypeLike, _DTypeLikeBool, diff --git a/numpy/typing/_dtype_like.py b/numpy/typing/_dtype_like.py index c9bf1a137..b705d82fd 100644 --- a/numpy/typing/_dtype_like.py +++ b/numpy/typing/_dtype_like.py @@ -57,9 +57,12 @@ from ._char_codes import ( _ObjectCodes, ) -_DTypeLikeNested = Any # TODO: wait for support for recursive types +_SCT = TypeVar("_SCT", bound=np.generic) _DType_co = TypeVar("_DType_co", covariant=True, bound=DType[Any]) +_DTypeLikeNested = Any # TODO: wait for support for recursive types + + # Mandatory keys class _DTypeDictBase(TypedDict): names: Sequence[str] @@ -82,6 +85,14 @@ class _SupportsDType(Protocol[_DType_co]): def dtype(self) -> _DType_co: ... +# A subset of `npt.DTypeLike` that can be parametrized w.r.t. `np.generic` +_DTypeLike = Union[ + "np.dtype[_SCT]", + Type[_SCT], + _SupportsDType["np.dtype[_SCT]"], +] + + # Would create a dtype[np.void] _VoidDTypeLike = Union[ # (flexible_dtype, itemsize) |
