diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index a2692168..ccd97c98 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -342,7 +342,6 @@ from ._typing import ( _ArrayLikeObject_co, _ArrayLikeTD64_co, _DTypeLike, - _DTypeLikeVoid, _NestedSequence, _NumberLike_co, _ScalarLike_co, @@ -5025,7 +5024,7 @@ class void(flexible[bytes | tuple[Any, ...]]): # type: ignore[misc] # pyright: @overload def __new__(cls, length_or_data: _nt.CoInteger_0d | bytes, /, dtype: None = None) -> Self: ... @overload - def __new__(cls, length_or_data: object, /, dtype: _DTypeLikeVoid) -> Self: ... + def __new__(cls, length_or_data: object, /, dtype: _nt.ToDTypeVoid) -> Self: ... # @type_check_only diff --git a/src/numpy-stubs/_core/einsumfunc.pyi b/src/numpy-stubs/_core/einsumfunc.pyi index fd27c45e..0eec57a1 100644 --- a/src/numpy-stubs/_core/einsumfunc.pyi +++ b/src/numpy-stubs/_core/einsumfunc.pyi @@ -12,13 +12,6 @@ from numpy._typing import ( _ArrayLikeInt_co, _ArrayLikeObject_co, _ArrayLikeUInt_co, - _DTypeLikeBool, - _DTypeLikeComplex, - _DTypeLikeComplex_co, - _DTypeLikeFloat, - _DTypeLikeInt, - _DTypeLikeObject, - _DTypeLikeUInt, ) __all__ = ["einsum", "einsum_path"] @@ -30,6 +23,14 @@ _OptimizeKind: TypeAlias = bool | Literal["greedy", "optimal"] | Sequence[str | _CastingSafe: TypeAlias = Literal["no", "equiv", "safe", "same_kind", "same_value"] _CastingUnsafe: TypeAlias = Literal["unsafe"] +_ToDTypeUInt: TypeAlias = ( + _nt.ToDTypeUInt8 | _nt.ToDTypeUInt16 | _nt.ToDTypeUInt32 | _nt.ToDTypeUInt64 | _nt.ToDTypeULong +) +_ToDTypeInt: TypeAlias = _nt.ToDTypeInt8 | _nt.ToDTypeInt16 | _nt.ToDTypeInt32 | _nt.ToDTypeInt64 | _nt.ToDTypeLong +_ToDTypeFloat: TypeAlias = _nt.ToDTypeFloat16 | _nt.ToDTypeFloat32 | _nt.ToDTypeFloat64 | _nt.ToDTypeLongDouble +_ToDTypeComplex: TypeAlias = _nt.ToDTypeComplex64 | _nt.ToDTypeComplex128 | _nt.ToDTypeCLongDouble +_ToDTypeComplex_co: TypeAlias = _nt.ToDTypeBool | _ToDTypeUInt | _ToDTypeInt | _ToDTypeFloat | _ToDTypeComplex + # TODO: Properly handle the `casting`-based combinatorics # TODO: We need to evaluate the content `__subscripts` in order # to identify whether or an array or scalar is returned. At a cursory @@ -43,7 +44,7 @@ def einsum( *operands: _ArrayLikeBool_co, out: None = None, optimize: _OptimizeKind = False, - dtype: _DTypeLikeBool | None = None, + dtype: _nt.ToDTypeBool | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", ) -> Incomplete: ... @@ -53,7 +54,7 @@ def einsum( /, *operands: _ArrayLikeUInt_co, out: None = None, - dtype: _DTypeLikeUInt | None = None, + dtype: _ToDTypeUInt | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -64,7 +65,7 @@ def einsum( /, *operands: _ArrayLikeInt_co, out: None = None, - dtype: _DTypeLikeInt | None = None, + dtype: _ToDTypeInt | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -75,7 +76,7 @@ def einsum( /, *operands: _ArrayLikeFloat_co, out: None = None, - dtype: _DTypeLikeFloat | None = None, + dtype: _ToDTypeFloat | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -86,7 +87,7 @@ def einsum( /, *operands: _ArrayLikeComplex_co, out: None = None, - dtype: _DTypeLikeComplex | None = None, + dtype: _ToDTypeComplex | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -97,7 +98,7 @@ def einsum( /, *operands: Any, casting: _CastingUnsafe, - dtype: _DTypeLikeComplex_co | None = None, + dtype: _ToDTypeComplex_co | None = None, out: None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, @@ -108,7 +109,7 @@ def einsum( /, *operands: _ArrayLikeComplex_co, out: _ArrayT, - dtype: _DTypeLikeComplex_co | None = None, + dtype: _ToDTypeComplex_co | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -120,7 +121,7 @@ def einsum( *operands: Any, out: _ArrayT, casting: _CastingUnsafe, - dtype: _DTypeLikeComplex_co | None = None, + dtype: _ToDTypeComplex_co | None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, ) -> _ArrayT: ... @@ -130,7 +131,7 @@ def einsum( /, *operands: _ArrayLikeObject_co, out: None = None, - dtype: _DTypeLikeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -141,7 +142,7 @@ def einsum( /, *operands: Any, casting: _CastingUnsafe, - dtype: _DTypeLikeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, out: None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, @@ -152,7 +153,7 @@ def einsum( /, *operands: _ArrayLikeObject_co, out: _ArrayT, - dtype: _DTypeLikeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -164,7 +165,7 @@ def einsum( *operands: Any, out: _ArrayT, casting: _CastingUnsafe, - dtype: _DTypeLikeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, ) -> _ArrayT: ... @@ -175,7 +176,7 @@ def einsum( def einsum_path( subscripts: str | _ArrayLikeInt_co, /, - *operands: _ArrayLikeComplex_co | _DTypeLikeObject, + *operands: _ArrayLikeComplex_co | _nt.ToDTypeObject, optimize: _OptimizeKind = "greedy", einsum_call: L[False] = False, ) -> tuple[list[str | tuple[int, ...]], str]: ... diff --git a/src/numpy-stubs/_core/umath.pyi b/src/numpy-stubs/_core/umath.pyi index 29fa38e6..07ec4ad2 100644 --- a/src/numpy-stubs/_core/umath.pyi +++ b/src/numpy-stubs/_core/umath.pyi @@ -18,7 +18,6 @@ from typing_extensions import TypeAliasType, TypeVar, Unpack import _numtype as _nt import numpy as np from numpy import _CastingKind, _OrderKACF # noqa: ICN003 -from numpy._typing import _DTypeLike as _ToDType, _DTypeLikeComplex as _ToDTypeComplex, _DTypeLikeFloat as _ToDTypeFloat from . import _multiarray_umath as _multiarray_umath from ._multiarray_umath import ( @@ -187,6 +186,9 @@ _ToStringLike: TypeAlias = bytes | str | np.character _CoFloat: TypeAlias = float | _nt.co_float _CoComplex: TypeAlias = complex | _nt.co_complex +_ToDTypeFloat: TypeAlias = _nt.ToDTypeFloat16 | _nt.ToDTypeFloat32 | _nt.ToDTypeFloat64 | _nt.ToDTypeLongDouble +_ToDTypeComplex: TypeAlias = _nt.ToDTypeComplex64 | _nt.ToDTypeComplex128 | _nt.ToDTypeCLongDouble + _ToDTypeInexact: TypeAlias = _ToDTypeFloat | _ToDTypeComplex _BoolND: TypeAlias = _nt.Array[np.bool_] @@ -250,7 +252,7 @@ class _Kwargs3_g(_KwargsCommon, total=False): class _Call11(Protocol): @overload # 0d, dtype: T def __call__( - self, x: _ToScalar, /, out: _Out1[None] = None, *, dtype: _ToDType[_ScalarT], **kw: Unpack[_Kwargs2] + self, x: _ToScalar, /, out: _Out1[None] = None, *, dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2] ) -> _ScalarT: ... @overload # 0d def __call__( @@ -262,7 +264,7 @@ class _Call11(Protocol): ) -> _ArrayT: ... @overload # ?d, out=..., dtype: T def __call__( - self, x: _nt.ToGeneric_nd, /, out: EllipsisType, *, dtype: _ToDType[_ScalarT], **kw: Unpack[_Kwargs2] + self, x: _nt.ToGeneric_nd, /, out: EllipsisType, *, dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2] ) -> _nt.Array[_ScalarT]: ... @overload # nd, dtype: T def __call__( @@ -271,7 +273,7 @@ class _Call11(Protocol): /, out: _Out1[_nt.Array | None] = None, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # nd @@ -834,7 +836,7 @@ class _Call11String(Protocol[_ScalarT_co]): /, out: _Out1[None] = None, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # ?d string-like, out=..., dtype: T @@ -844,7 +846,7 @@ class _Call11String(Protocol[_ScalarT_co]): /, out: EllipsisType, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # ? @@ -862,7 +864,7 @@ class _Call11String(Protocol[_ScalarT_co]): class _Call12(Protocol): @overload # 0d, dtype: T def __call__( - self, x: _ToScalar, /, *, out: _Out2[None] = ..., dtype: _ToDType[_ScalarT], **kw: Unpack[_Kwargs3] + self, x: _ToScalar, /, *, out: _Out2[None] = ..., dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3] ) -> _Out2[_ScalarT]: ... @overload # 0d def __call__( @@ -886,11 +888,11 @@ class _Call12(Protocol): ) -> tuple[_nt.Array[Incomplete], _nt.Array[Incomplete]]: ... @overload # ?d, out=..., dtype: T def __call__( - self, x: _nt.ToGeneric_nd, /, *, out: EllipsisType, dtype: _ToDType[_ScalarT], **kw: Unpack[_Kwargs3] + self, x: _nt.ToGeneric_nd, /, *, out: EllipsisType, dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3] ) -> tuple[_nt.Array[_ScalarT], _nt.Array[_ScalarT]]: ... @overload # nd, dtype: T def __call__( - self, x: _nt.ToGeneric_1nd, /, *, out: _Out2[None] = ..., dtype: _ToDType[_ScalarT], **kw: Unpack[_Kwargs3] + self, x: _nt.ToGeneric_1nd, /, *, out: _Out2[None] = ..., dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3] ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # nd def __call__( @@ -923,7 +925,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _ScalarT: ... @overload # 0d, 0d @@ -942,7 +944,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # nd, ?d, dtype: T @@ -953,7 +955,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, ?d, out=..., dtype: T @@ -964,7 +966,7 @@ class _Call21(Protocol): /, out: EllipsisType, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, nd @@ -1201,7 +1203,7 @@ class _Call21Float(Protocol): /, out: EllipsisType, *, - dtype: _ToDType[_FloatT], + dtype: _nt._ToDType[_FloatT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_FloatT]: ... @overload # ?d +floating, nd +floating, dtype: T @@ -1212,7 +1214,7 @@ class _Call21Float(Protocol): /, out: _Out1[None] = None, *, - dtype: _ToDType[_FloatT], + dtype: _nt._ToDType[_FloatT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_FloatT]: ... @overload # nd +floating, ?d +floating, dtype: T @@ -1223,7 +1225,7 @@ class _Call21Float(Protocol): /, out: _Out1[None] = None, *, - dtype: _ToDType[_FloatT], + dtype: _nt._ToDType[_FloatT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_FloatT]: ... @overload # ?d +floating, nd ~floating @@ -1443,7 +1445,7 @@ class _Call22(Protocol): /, *, out: _Out2[None] = ..., - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_ScalarT]: ... @overload # 0d, 0d @@ -1465,7 +1467,7 @@ class _Call22(Protocol): /, *, out: _Out2[_nt.Array[_ScalarT] | None] = ..., - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # ?d, nd, dtype: T @@ -1476,7 +1478,7 @@ class _Call22(Protocol): /, *, out: _Out2[_nt.Array[_ScalarT] | None] = ..., - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # ?d, ?d, out=..., dtype: T @@ -1487,7 +1489,7 @@ class _Call22(Protocol): /, *, out: EllipsisType, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # ?d, ?d, out: (T1, None) @@ -1634,7 +1636,7 @@ class _Accumulate2(Protocol): a: _nt.ToGeneric_nd, /, axis: SupportsIndex, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _nt.Array[_ScalarT] | EllipsisType | None = None, ) -> _nt.Array[_ScalarT]: ... @overload # ?d, *, dtype: T @@ -1644,7 +1646,7 @@ class _Accumulate2(Protocol): /, axis: SupportsIndex = 0, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _Out1[None] | EllipsisType = None, ) -> _nt.Array[_ScalarT]: ... @overload # ?d @@ -1685,7 +1687,7 @@ class _ReduceAt2(Protocol): ixs: _nt.CoInteger_nd, /, axis: SupportsIndex, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _nt.Array[_ScalarT] | EllipsisType | None = None, ) -> _nt.Array[_ScalarT]: ... @overload @@ -1696,7 +1698,7 @@ class _ReduceAt2(Protocol): /, axis: SupportsIndex = 0, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _nt.Array[_ScalarT] | EllipsisType | None = None, ) -> _nt.Array[_ScalarT]: ... @overload @@ -1733,7 +1735,7 @@ class _Outer1(Protocol): /, *, out: _Out1[_nt.Array[_ScalarT] | None] | EllipsisType = None, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, ?d @@ -1790,7 +1792,7 @@ class _Outer2(Protocol): B: _nt.ToGeneric_nd, /, *, - dtype: _ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _Out2[_nt.Array[_ScalarT] | None] | EllipsisType = ..., **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... diff --git a/src/numpy-stubs/_typing/__init__.pyi b/src/numpy-stubs/_typing/__init__.pyi index 004c2eaf..674fe520 100644 --- a/src/numpy-stubs/_typing/__init__.pyi +++ b/src/numpy-stubs/_typing/__init__.pyi @@ -79,18 +79,6 @@ from ._char_codes import ( from ._dtype_like import ( DTypeLike as DTypeLike, _DTypeLike as _DTypeLike, - _DTypeLikeBool as _DTypeLikeBool, - _DTypeLikeBytes as _DTypeLikeBytes, - _DTypeLikeComplex as _DTypeLikeComplex, - _DTypeLikeComplex_co as _DTypeLikeComplex_co, - _DTypeLikeDT64 as _DTypeLikeDT64, - _DTypeLikeFloat as _DTypeLikeFloat, - _DTypeLikeInt as _DTypeLikeInt, - _DTypeLikeObject as _DTypeLikeObject, - _DTypeLikeStr as _DTypeLikeStr, - _DTypeLikeTD64 as _DTypeLikeTD64, - _DTypeLikeUInt as _DTypeLikeUInt, - _DTypeLikeVoid as _DTypeLikeVoid, _SupportsDType as _SupportsDType, _VoidDTypeLike as _VoidDTypeLike, ) diff --git a/src/numpy-stubs/_typing/_dtype_like.pyi b/src/numpy-stubs/_typing/_dtype_like.pyi index dfd68a3f..595e407e 100644 --- a/src/numpy-stubs/_typing/_dtype_like.pyi +++ b/src/numpy-stubs/_typing/_dtype_like.pyi @@ -5,21 +5,6 @@ from typing_extensions import TypeVar import numpy as np -from ._char_codes import ( - _BoolCodes, - _BytesCodes, - _ComplexFloatingCodes, - _DT64Codes, - _FloatingCodes, - _NumberCodes, - _ObjectCodes, - _SignedIntegerCodes, - _StrCodes, - _TD64Codes, - _UnsignedIntegerCodes, - _VoidCodes, -) - _ScalarT = TypeVar("_ScalarT", bound=np.generic) _DTypeT = TypeVar("_DTypeT", bound=np.dtype) _DTypeT_co = TypeVar("_DTypeT_co", covariant=True, bound=np.dtype) @@ -56,26 +41,6 @@ _DTypeLike: TypeAlias = type[_ScalarT] | np.dtype[_ScalarT] | _SupportsDType[np. # Would create a dtype[np.void] _VoidDTypeLike: TypeAlias = tuple[Any, Any] | list[Any] | _DTypeDict -# TODO(jorenahm): remove these `_DTypeLike*` aliases in favor of `_numtype.ToDType*`: -# https://github.com/numpy/numtype/issues/566 -# ruff: noqa: PYI047 - -# Aliases for commonly used dtype-like objects. -# Note that the precision of `np.number` subclasses is ignored herein. -_DTypeLikeBool: TypeAlias = type[bool] | _DTypeLike[np.bool] | _BoolCodes -_DTypeLikeUInt: TypeAlias = _DTypeLike[np.unsignedinteger] | _UnsignedIntegerCodes -_DTypeLikeInt: TypeAlias = type[int] | _DTypeLike[np.signedinteger] | _SignedIntegerCodes -_DTypeLikeFloat: TypeAlias = type[float] | _DTypeLike[np.floating] | _FloatingCodes -_DTypeLikeComplex: TypeAlias = type[complex] | _DTypeLike[np.complexfloating] | _ComplexFloatingCodes -_DTypeLikeDT64: TypeAlias = _DTypeLike[np.timedelta64] | _TD64Codes -_DTypeLikeTD64: TypeAlias = _DTypeLike[np.datetime64] | _DT64Codes -_DTypeLikeStr: TypeAlias = type[str] | _DTypeLike[np.str_] | _StrCodes -_DTypeLikeBytes: TypeAlias = type[bytes] | _DTypeLike[np.bytes_] | _BytesCodes -_DTypeLikeVoid: TypeAlias = _DTypeLike[np.void] | _VoidCodes | _VoidDTypeLike -_DTypeLikeObject: TypeAlias = type | _DTypeLike[np.object_] | _ObjectCodes - -_DTypeLikeComplex_co: TypeAlias = type[complex] | _DTypeLike[np.number] | _NumberCodes | _BoolCodes - # NOTE: while it is possible to provide the dtype as a dict of # dtype-like objects (e.g. `{'field1': ..., 'field2': ..., ...}`), # this syntax is officially discouraged and diff --git a/src/numpy-stubs/lib/recfunctions.pyi b/src/numpy-stubs/lib/recfunctions.pyi index c009886d..b862c7d2 100644 --- a/src/numpy-stubs/lib/recfunctions.pyi +++ b/src/numpy-stubs/lib/recfunctions.pyi @@ -6,7 +6,6 @@ from typing_extensions import TypeVar import _numtype as _nt import numpy as np import numpy.typing as npt -from numpy._typing import _DTypeLike, _DTypeLikeVoid from numpy.ma.mrecords import MaskedRecords __all__ = [ @@ -227,7 +226,7 @@ def repack_fields(a: _ArrayT, align: bool = False, recurse: bool = False) -> _Ar # TODO(jorenham): Attempt shape-typing (return type has ndim == arr.ndim + 1) @overload def structured_to_unstructured( - arr: _nt.Array[np.void], dtype: _DTypeLike[_ScalarT], copy: bool = False, casting: np._CastingKind = "unsafe" + arr: _nt.Array[np.void], dtype: _nt._ToDType[_ScalarT], copy: bool = False, casting: np._CastingKind = "unsafe" ) -> _nt.Array[_ScalarT]: ... @overload def structured_to_unstructured( @@ -274,7 +273,7 @@ def assign_fields_by_name(dst: _nt.Array[np.void], src: _nt.Array[np.void], zero # def require_fields( - array: _nt.Array[np.void, _ShapeT], required_dtype: _DTypeLikeVoid + array: _nt.Array[np.void, _ShapeT], required_dtype: _nt.ToDTypeVoid ) -> _nt.Array[np.void, _ShapeT]: ... # TODO(jorenham): Attempt shape-typing diff --git a/src/numpy-stubs/random/_generator.pyi b/src/numpy-stubs/random/_generator.pyi index f041becb..ef238fe5 100644 --- a/src/numpy-stubs/random/_generator.pyi +++ b/src/numpy-stubs/random/_generator.pyi @@ -6,7 +6,7 @@ from typing_extensions import TypeVar, override import _numtype as _nt import numpy as np import numpy.typing as npt -from numpy._typing import _ArrayLike, _BoolCodes, _DTypeLike +from numpy._typing import _ArrayLike, _BoolCodes from numpy.random import BitGenerator, RandomState, SeedSequence ### @@ -15,7 +15,7 @@ _ScalarT = TypeVar("_ScalarT", bound=np.generic) _IntegerT = TypeVar("_IntegerT", bound=_nt.co_integer) _ShapeT = TypeVar("_ShapeT", bound=_nt.Shape) -_DTypeLikeFloat: TypeAlias = _nt.ToDTypeFloat32 | _nt.ToDTypeFloat64 +_ToDTypeFloat: TypeAlias = _nt.ToDTypeFloat32 | _nt.ToDTypeFloat64 _CoInt_nnd: TypeAlias = _nt._ToArray_nnd[_nt.co_integer] _CoFloat_nnd: TypeAlias = _nt._ToArray_nnd[_nt.co_float] @@ -139,7 +139,7 @@ class Generator: # @overload - def random(self, /, size: None = None, dtype: _DTypeLikeFloat = ..., out: None = None) -> float: ... + def random(self, /, size: None = None, dtype: _ToDTypeFloat = ..., out: None = None) -> float: ... @overload def random( self, @@ -243,7 +243,7 @@ class Generator: # @overload def standard_exponential( - self, /, size: None = None, dtype: _DTypeLikeFloat = ..., method: _ExpMethod = "zig", out: None = None + self, /, size: None = None, dtype: _ToDTypeFloat = ..., method: _ExpMethod = "zig", out: None = None ) -> float: ... @overload def standard_exponential( @@ -458,7 +458,7 @@ class Generator: # @overload - def standard_normal(self, /, size: None = None, dtype: _DTypeLikeFloat = ..., out: None = None) -> float: ... + def standard_normal(self, /, size: None = None, dtype: _ToDTypeFloat = ..., out: None = None) -> float: ... @overload def standard_normal( self, /, size: _nt.ToShape | None = None, dtype: _nt.ToDTypeFloat64 = ..., *, out: _nt.Array[np.float64] @@ -587,7 +587,7 @@ class Generator: ) -> float | _nt.Array[np.float32]: ... @overload def standard_gamma( - self, /, shape: _nt.CoFloating_0d, size: None = None, dtype: _DTypeLikeFloat = ..., out: None = None + self, /, shape: _nt.CoFloating_0d, size: None = None, dtype: _ToDTypeFloat = ..., out: None = None ) -> float: ... @overload def standard_gamma( @@ -751,7 +751,7 @@ class Generator: low: int, high: int | None = None, size: None = None, - dtype: _DTypeLike[np.int64] = ..., + dtype: _nt._ToDType[np.int64] = ..., endpoint: bool = False, ) -> np.int64: ... @overload @@ -766,7 +766,7 @@ class Generator: high: int | None = None, size: None = None, *, - dtype: _DTypeLike[_IntegerT], + dtype: _nt._ToDType[_IntegerT], endpoint: bool = False, ) -> _IntegerT: ... @overload @@ -861,7 +861,7 @@ class Generator: low: _nt.CoInteger_nd, high: _nt.CoInteger_nd, size: _nt.ToShape, - dtype: _DTypeLike[np.int64] = ..., + dtype: _nt._ToDType[np.int64] = ..., endpoint: bool = False, ) -> _nt.Array[np.int64]: ... @overload @@ -871,7 +871,7 @@ class Generator: low: _nt.CoInteger_nd, high: _nt.CoInteger_nd, size: _nt.ToShape, - dtype: _DTypeLike[_IntegerT], + dtype: _nt._ToDType[_IntegerT], endpoint: bool = False, ) -> _nt.Array[_IntegerT]: ... @overload @@ -972,7 +972,7 @@ class Generator: high: _nt.CoInteger_nd | None = None, *, size: _nt.ToShape, - dtype: _DTypeLike[np.int64] = ..., + dtype: _nt._ToDType[np.int64] = ..., endpoint: bool = False, ) -> _nt.Array[np.int64]: ... @overload @@ -983,7 +983,7 @@ class Generator: high: _nt.CoInteger_nd | None = None, *, size: _nt.ToShape, - dtype: _DTypeLike[_IntegerT], + dtype: _nt._ToDType[_IntegerT], endpoint: bool = False, ) -> _nt.Array[_IntegerT]: ... @overload @@ -1104,7 +1104,7 @@ class Generator: high: _nt.CoInteger_nd | None = None, size: _nt.ToShape | None = None, *, - dtype: _DTypeLike[_IntegerT], + dtype: _nt._ToDType[_IntegerT], endpoint: bool = False, ) -> _IntegerT | _nt.Array[_IntegerT]: ... @overload diff --git a/src/numpy-stubs/random/bit_generator.pyi b/src/numpy-stubs/random/bit_generator.pyi index c6890560..fbfa832b 100644 --- a/src/numpy-stubs/random/bit_generator.pyi +++ b/src/numpy-stubs/random/bit_generator.pyi @@ -2,23 +2,12 @@ import abc from _typeshed import Incomplete from collections.abc import Callable, Mapping, Sequence from threading import Lock -from typing import ( - Any, - ClassVar, - Generic, - Literal as L, - NamedTuple, - Self, - TypeAlias, - TypedDict, - overload, - type_check_only, -) +from typing import Any, ClassVar, Generic, Literal as L, NamedTuple, Self, TypedDict, overload, type_check_only from typing_extensions import CapsuleType, TypeVar, override import _numtype as _nt import numpy as np -from numpy._typing import _ArrayLikeInt_co, _DTypeLike, _UInt32Codes, _UInt64Codes +from numpy._typing import _ArrayLikeInt_co __all__ = ["BitGenerator", "SeedSequence"] @@ -26,9 +15,6 @@ __all__ = ["BitGenerator", "SeedSequence"] _StateT = TypeVar("_StateT", bound=Mapping[str, object], default=Mapping[str, Any]) -_ToDTypeUInt32: TypeAlias = _DTypeLike[np.uint32] | _UInt32Codes -_ToDTypeUInt64: TypeAlias = _DTypeLike[np.uint64] | _UInt64Codes - ### @type_check_only @@ -55,12 +41,12 @@ class _CythonMixin: @type_check_only class _GenerateStateMixin(_CythonMixin): @overload - def generate_state(self, /, n_words: int, dtype: _ToDTypeUInt32 = ...) -> _nt.Array[np.uint32]: ... + def generate_state(self, /, n_words: int, dtype: _nt.ToDTypeUInt32 = ...) -> _nt.Array[np.uint32]: ... @overload - def generate_state(self, /, n_words: int, dtype: _ToDTypeUInt64) -> _nt.Array[np.uint64]: ... + def generate_state(self, /, n_words: int, dtype: _nt.ToDTypeUInt64) -> _nt.Array[np.uint64]: ... @overload def generate_state( - self, /, n_words: int, dtype: _ToDTypeUInt32 | _ToDTypeUInt64 = ... + self, /, n_words: int, dtype: _nt.ToDTypeUInt32 | _nt.ToDTypeUInt64 = ... ) -> _nt.Array[np.uint32 | np.uint64]: ... ### @@ -104,7 +90,7 @@ class BitGenerator(_CythonMixin, abc.ABC, Generic[_StateT]): class ISeedSequence(abc.ABC): @abc.abstractmethod def generate_state( - self, /, n_words: int, dtype: _ToDTypeUInt32 | _ToDTypeUInt64 = ... + self, /, n_words: int, dtype: _nt.ToDTypeUInt32 | _nt.ToDTypeUInt64 = ... ) -> _nt.Array[np.uint32 | np.uint64]: ... class ISpawnableSeedSequence(ISeedSequence, abc.ABC): diff --git a/src/numpy-stubs/random/mtrand.pyi b/src/numpy-stubs/random/mtrand.pyi index 5f4acd2c..eebc256d 100644 --- a/src/numpy-stubs/random/mtrand.pyi +++ b/src/numpy-stubs/random/mtrand.pyi @@ -6,7 +6,7 @@ from typing_extensions import TypeVar, override import _numtype as _nt import numpy as np import numpy.typing as npt -from numpy._typing import _ArrayLike, _BoolCodes, _DTypeLike +from numpy._typing import _ArrayLike, _BoolCodes from numpy.random.bit_generator import BitGenerator __all__ = [ @@ -485,7 +485,7 @@ class RandomState: def randint(self, /, low: int, high: int | None = None, size: None = None, *, dtype: type[_nt.JustInt]) -> int: ... @overload def randint( # type: ignore[overload-overlap] - self, /, low: int, high: int | None = None, size: None = None, *, dtype: _DTypeLike[_IntegerT] + self, /, low: int, high: int | None = None, size: None = None, *, dtype: _nt._ToDType[_IntegerT] ) -> _IntegerT: ... @overload def randint(self, /, low: int, high: int | None = None, size: None = None, *, dtype: _BoolCodes) -> np.bool: ... @@ -529,7 +529,7 @@ class RandomState: ) -> _nt.Array[np.bool]: ... @overload def randint( # type: ignore[overload-overlap] - self, /, low: _nt.CoInteger_nd, high: _nt.CoInteger_nd, size: _nt.ToShape, dtype: _DTypeLike[_IntegerT] + self, /, low: _nt.CoInteger_nd, high: _nt.CoInteger_nd, size: _nt.ToShape, dtype: _nt._ToDType[_IntegerT] ) -> _nt.Array[_IntegerT]: ... @overload def randint( @@ -585,7 +585,7 @@ class RandomState: high: _nt.CoInteger_nd | None = None, *, size: _nt.ToShape, - dtype: _DTypeLike[_IntegerT], + dtype: _nt._ToDType[_IntegerT], ) -> _nt.Array[_IntegerT]: ... @overload def randint( @@ -689,7 +689,7 @@ class RandomState: high: _nt.CoInteger_nd | None = None, size: _nt.ToShape | None = None, *, - dtype: _DTypeLike[_IntegerT], + dtype: _nt._ToDType[_IntegerT], ) -> _IntegerT | _nt.Array[_IntegerT]: ... @overload def randint(