From ba311664e03bb8eaa8cb335e9d2e4108872ea823 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 15 Apr 2026 18:09:19 +0000 Subject: [PATCH 1/4] remove the numpy._typing._DTypeLike{} aliases in favor of _numtype.ToDType --- src/numpy-stubs/__init__.pyi | 3 +- src/numpy-stubs/_core/einsumfunc.pyi | 43 +++++++++++++----------- src/numpy-stubs/_core/umath.pyi | 5 ++- src/numpy-stubs/_typing/__init__.pyi | 12 ------- src/numpy-stubs/_typing/_dtype_like.pyi | 35 ------------------- src/numpy-stubs/lib/recfunctions.pyi | 4 +-- src/numpy-stubs/random/_generator.pyi | 26 +++++++------- src/numpy-stubs/random/bit_generator.pyi | 6 ++-- src/numpy-stubs/random/mtrand.pyi | 10 +++--- 9 files changed, 51 insertions(+), 93 deletions(-) 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..fc9ce33e 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,16 @@ _OptimizeKind: TypeAlias = bool | Literal["greedy", "optimal"] | Sequence[str | _CastingSafe: TypeAlias = Literal["no", "equiv", "safe", "same_kind", "same_value"] _CastingUnsafe: TypeAlias = Literal["unsafe"] +_ToDTypeBool: TypeAlias = _nt.ToDTypeBool +_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 = _ToDTypeBool | _ToDTypeUInt | _ToDTypeInt | _ToDTypeFloat | _ToDTypeComplex +_ToDTypeObject: TypeAlias = _nt.ToDTypeObject + # 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 +46,7 @@ def einsum( *operands: _ArrayLikeBool_co, out: None = None, optimize: _OptimizeKind = False, - dtype: _DTypeLikeBool | None = None, + dtype: _ToDTypeBool | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", ) -> Incomplete: ... @@ -53,7 +56,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 +67,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 +78,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 +89,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 +100,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 +111,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 +123,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 +133,7 @@ def einsum( /, *operands: _ArrayLikeObject_co, out: None = None, - dtype: _DTypeLikeObject | None = None, + dtype: _ToDTypeObject | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -141,7 +144,7 @@ def einsum( /, *operands: Any, casting: _CastingUnsafe, - dtype: _DTypeLikeObject | None = None, + dtype: _ToDTypeObject | None = None, out: None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, @@ -152,7 +155,7 @@ def einsum( /, *operands: _ArrayLikeObject_co, out: _ArrayT, - dtype: _DTypeLikeObject | None = None, + dtype: _ToDTypeObject | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -164,7 +167,7 @@ def einsum( *operands: Any, out: _ArrayT, casting: _CastingUnsafe, - dtype: _DTypeLikeObject | None = None, + dtype: _ToDTypeObject | None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, ) -> _ArrayT: ... @@ -175,7 +178,7 @@ def einsum( def einsum_path( subscripts: str | _ArrayLikeInt_co, /, - *operands: _ArrayLikeComplex_co | _DTypeLikeObject, + *operands: _ArrayLikeComplex_co | _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..23956460 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,10 @@ _ToStringLike: TypeAlias = bytes | str | np.character _CoFloat: TypeAlias = float | _nt.co_float _CoComplex: TypeAlias = complex | _nt.co_complex +_ToDType = _nt._ToDType +_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_] 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..afd76f75 100644 --- a/src/numpy-stubs/lib/recfunctions.pyi +++ b/src/numpy-stubs/lib/recfunctions.pyi @@ -6,7 +6,7 @@ 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._typing import _DTypeLike from numpy.ma.mrecords import MaskedRecords __all__ = [ @@ -274,7 +274,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..bd006f8b 100644 --- a/src/numpy-stubs/random/bit_generator.pyi +++ b/src/numpy-stubs/random/bit_generator.pyi @@ -18,7 +18,7 @@ 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,8 +26,8 @@ __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 +_ToDTypeUInt32: TypeAlias = _nt.ToDTypeUInt32 +_ToDTypeUInt64: TypeAlias = _nt.ToDTypeUInt64 ### 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( From f7c607225a592cd4ea166bb5adcf641a3a78d815 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 15 Apr 2026 22:25:28 +0000 Subject: [PATCH 2/4] remove the numpy._typing._DTypeLike{} aliases in favor of _numtype.ToDType --- src/numpy-stubs/_core/umath.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/numpy-stubs/_core/umath.pyi b/src/numpy-stubs/_core/umath.pyi index 23956460..f4ad9d5b 100644 --- a/src/numpy-stubs/_core/umath.pyi +++ b/src/numpy-stubs/_core/umath.pyi @@ -186,7 +186,7 @@ _ToStringLike: TypeAlias = bytes | str | np.character _CoFloat: TypeAlias = float | _nt.co_float _CoComplex: TypeAlias = complex | _nt.co_complex -_ToDType = _nt._ToDType +_ToDType = TypeAliasType("_ToDType", _nt._ToDType[_ScalarT], type_params=(_ScalarT,)) _ToDTypeFloat: TypeAlias = _nt.ToDTypeFloat16 | _nt.ToDTypeFloat32 | _nt.ToDTypeFloat64 | _nt.ToDTypeLongDouble _ToDTypeComplex: TypeAlias = _nt.ToDTypeComplex64 | _nt.ToDTypeComplex128 | _nt.ToDTypeCLongDouble From 5aad82d90b287502f6fa14d88384c1942fb98685 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 18 Apr 2026 18:07:52 +0000 Subject: [PATCH 3/4] remove unnecessary local aliases, use _nt types directly --- src/numpy-stubs/_core/einsumfunc.pyi | 16 ++++---- src/numpy-stubs/_core/umath.pyi | 51 ++++++++++++------------ src/numpy-stubs/lib/recfunctions.pyi | 3 +- src/numpy-stubs/random/bit_generator.pyi | 24 +++-------- 4 files changed, 38 insertions(+), 56 deletions(-) diff --git a/src/numpy-stubs/_core/einsumfunc.pyi b/src/numpy-stubs/_core/einsumfunc.pyi index fc9ce33e..0eec57a1 100644 --- a/src/numpy-stubs/_core/einsumfunc.pyi +++ b/src/numpy-stubs/_core/einsumfunc.pyi @@ -23,15 +23,13 @@ _OptimizeKind: TypeAlias = bool | Literal["greedy", "optimal"] | Sequence[str | _CastingSafe: TypeAlias = Literal["no", "equiv", "safe", "same_kind", "same_value"] _CastingUnsafe: TypeAlias = Literal["unsafe"] -_ToDTypeBool: TypeAlias = _nt.ToDTypeBool _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 = _ToDTypeBool | _ToDTypeUInt | _ToDTypeInt | _ToDTypeFloat | _ToDTypeComplex -_ToDTypeObject: TypeAlias = _nt.ToDTypeObject +_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 @@ -46,7 +44,7 @@ def einsum( *operands: _ArrayLikeBool_co, out: None = None, optimize: _OptimizeKind = False, - dtype: _ToDTypeBool | None = None, + dtype: _nt.ToDTypeBool | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", ) -> Incomplete: ... @@ -133,7 +131,7 @@ def einsum( /, *operands: _ArrayLikeObject_co, out: None = None, - dtype: _ToDTypeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -144,7 +142,7 @@ def einsum( /, *operands: Any, casting: _CastingUnsafe, - dtype: _ToDTypeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, out: None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, @@ -155,7 +153,7 @@ def einsum( /, *operands: _ArrayLikeObject_co, out: _ArrayT, - dtype: _ToDTypeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, order: _OrderKACF = "K", casting: _CastingSafe = "safe", optimize: _OptimizeKind = False, @@ -167,7 +165,7 @@ def einsum( *operands: Any, out: _ArrayT, casting: _CastingUnsafe, - dtype: _ToDTypeObject | None = None, + dtype: _nt.ToDTypeObject | None = None, order: _OrderKACF = "K", optimize: _OptimizeKind = False, ) -> _ArrayT: ... @@ -178,7 +176,7 @@ def einsum( def einsum_path( subscripts: str | _ArrayLikeInt_co, /, - *operands: _ArrayLikeComplex_co | _ToDTypeObject, + *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 f4ad9d5b..585e8b32 100644 --- a/src/numpy-stubs/_core/umath.pyi +++ b/src/numpy-stubs/_core/umath.pyi @@ -186,7 +186,6 @@ _ToStringLike: TypeAlias = bytes | str | np.character _CoFloat: TypeAlias = float | _nt.co_float _CoComplex: TypeAlias = complex | _nt.co_complex -_ToDType = TypeAliasType("_ToDType", _nt._ToDType[_ScalarT], type_params=(_ScalarT,)) _ToDTypeFloat: TypeAlias = _nt.ToDTypeFloat16 | _nt.ToDTypeFloat32 | _nt.ToDTypeFloat64 | _nt.ToDTypeLongDouble _ToDTypeComplex: TypeAlias = _nt.ToDTypeComplex64 | _nt.ToDTypeComplex128 | _nt.ToDTypeCLongDouble @@ -253,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__( @@ -265,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__( @@ -274,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 @@ -837,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 @@ -847,7 +846,7 @@ class _Call11String(Protocol[_ScalarT_co]): /, out: EllipsisType, *, - dtype: _ToDType[_ScalarT], + dtype: _nt.ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # ? @@ -865,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__( @@ -889,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__( @@ -926,7 +925,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _ToDType[_ScalarT], + dtype: _nt.ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _ScalarT: ... @overload # 0d, 0d @@ -945,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 @@ -956,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 @@ -967,7 +966,7 @@ class _Call21(Protocol): /, out: EllipsisType, *, - dtype: _ToDType[_ScalarT], + dtype: _nt.ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, nd @@ -1204,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 @@ -1215,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 @@ -1226,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 @@ -1446,7 +1445,7 @@ class _Call22(Protocol): /, *, out: _Out2[None] = ..., - dtype: _ToDType[_ScalarT], + dtype: _nt.ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_ScalarT]: ... @overload # 0d, 0d @@ -1468,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 @@ -1479,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 @@ -1490,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) @@ -1637,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 @@ -1647,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 @@ -1688,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 @@ -1699,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 @@ -1736,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 @@ -1793,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/lib/recfunctions.pyi b/src/numpy-stubs/lib/recfunctions.pyi index afd76f75..31a8e14b 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 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( diff --git a/src/numpy-stubs/random/bit_generator.pyi b/src/numpy-stubs/random/bit_generator.pyi index bd006f8b..fbfa832b 100644 --- a/src/numpy-stubs/random/bit_generator.pyi +++ b/src/numpy-stubs/random/bit_generator.pyi @@ -2,18 +2,7 @@ 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 @@ -26,9 +15,6 @@ __all__ = ["BitGenerator", "SeedSequence"] _StateT = TypeVar("_StateT", bound=Mapping[str, object], default=Mapping[str, Any]) -_ToDTypeUInt32: TypeAlias = _nt.ToDTypeUInt32 -_ToDTypeUInt64: TypeAlias = _nt.ToDTypeUInt64 - ### @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): From 20ed1276cb35f5910d51f83ab1d4134046f169c1 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sun, 19 Apr 2026 13:34:14 +0000 Subject: [PATCH 4/4] rename _nt.ToDType to _nt._ToDType --- src/numpy-stubs/_core/umath.pyi | 50 ++++++++++++++-------------- src/numpy-stubs/lib/recfunctions.pyi | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/numpy-stubs/_core/umath.pyi b/src/numpy-stubs/_core/umath.pyi index 585e8b32..07ec4ad2 100644 --- a/src/numpy-stubs/_core/umath.pyi +++ b/src/numpy-stubs/_core/umath.pyi @@ -252,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: _nt.ToDType[_ScalarT], **kw: Unpack[_Kwargs2] + self, x: _ToScalar, /, out: _Out1[None] = None, *, dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2] ) -> _ScalarT: ... @overload # 0d def __call__( @@ -264,7 +264,7 @@ class _Call11(Protocol): ) -> _ArrayT: ... @overload # ?d, out=..., dtype: T def __call__( - self, x: _nt.ToGeneric_nd, /, out: EllipsisType, *, dtype: _nt.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__( @@ -273,7 +273,7 @@ class _Call11(Protocol): /, out: _Out1[_nt.Array | None] = None, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # nd @@ -836,7 +836,7 @@ class _Call11String(Protocol[_ScalarT_co]): /, out: _Out1[None] = None, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # ?d string-like, out=..., dtype: T @@ -846,7 +846,7 @@ class _Call11String(Protocol[_ScalarT_co]): /, out: EllipsisType, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs2], ) -> _nt.Array[_ScalarT]: ... @overload # ? @@ -864,7 +864,7 @@ class _Call11String(Protocol[_ScalarT_co]): class _Call12(Protocol): @overload # 0d, dtype: T def __call__( - self, x: _ToScalar, /, *, out: _Out2[None] = ..., dtype: _nt.ToDType[_ScalarT], **kw: Unpack[_Kwargs3] + self, x: _ToScalar, /, *, out: _Out2[None] = ..., dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3] ) -> _Out2[_ScalarT]: ... @overload # 0d def __call__( @@ -888,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: _nt.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: _nt.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__( @@ -925,7 +925,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _ScalarT: ... @overload # 0d, 0d @@ -944,7 +944,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # nd, ?d, dtype: T @@ -955,7 +955,7 @@ class _Call21(Protocol): /, out: _Out1[None] = None, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, ?d, out=..., dtype: T @@ -966,7 +966,7 @@ class _Call21(Protocol): /, out: EllipsisType, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, nd @@ -1203,7 +1203,7 @@ class _Call21Float(Protocol): /, out: EllipsisType, *, - dtype: _nt.ToDType[_FloatT], + dtype: _nt._ToDType[_FloatT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_FloatT]: ... @overload # ?d +floating, nd +floating, dtype: T @@ -1214,7 +1214,7 @@ class _Call21Float(Protocol): /, out: _Out1[None] = None, *, - dtype: _nt.ToDType[_FloatT], + dtype: _nt._ToDType[_FloatT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_FloatT]: ... @overload # nd +floating, ?d +floating, dtype: T @@ -1225,7 +1225,7 @@ class _Call21Float(Protocol): /, out: _Out1[None] = None, *, - dtype: _nt.ToDType[_FloatT], + dtype: _nt._ToDType[_FloatT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_FloatT]: ... @overload # ?d +floating, nd ~floating @@ -1445,7 +1445,7 @@ class _Call22(Protocol): /, *, out: _Out2[None] = ..., - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_ScalarT]: ... @overload # 0d, 0d @@ -1467,7 +1467,7 @@ class _Call22(Protocol): /, *, out: _Out2[_nt.Array[_ScalarT] | None] = ..., - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # ?d, nd, dtype: T @@ -1478,7 +1478,7 @@ class _Call22(Protocol): /, *, out: _Out2[_nt.Array[_ScalarT] | None] = ..., - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # ?d, ?d, out=..., dtype: T @@ -1489,7 +1489,7 @@ class _Call22(Protocol): /, *, out: EllipsisType, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs4], ) -> _Out2[_nt.Array[_ScalarT]]: ... @overload # ?d, ?d, out: (T1, None) @@ -1636,7 +1636,7 @@ class _Accumulate2(Protocol): a: _nt.ToGeneric_nd, /, axis: SupportsIndex, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _nt.Array[_ScalarT] | EllipsisType | None = None, ) -> _nt.Array[_ScalarT]: ... @overload # ?d, *, dtype: T @@ -1646,7 +1646,7 @@ class _Accumulate2(Protocol): /, axis: SupportsIndex = 0, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _Out1[None] | EllipsisType = None, ) -> _nt.Array[_ScalarT]: ... @overload # ?d @@ -1687,7 +1687,7 @@ class _ReduceAt2(Protocol): ixs: _nt.CoInteger_nd, /, axis: SupportsIndex, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _nt.Array[_ScalarT] | EllipsisType | None = None, ) -> _nt.Array[_ScalarT]: ... @overload @@ -1698,7 +1698,7 @@ class _ReduceAt2(Protocol): /, axis: SupportsIndex = 0, *, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], out: _nt.Array[_ScalarT] | EllipsisType | None = None, ) -> _nt.Array[_ScalarT]: ... @overload @@ -1735,7 +1735,7 @@ class _Outer1(Protocol): /, *, out: _Out1[_nt.Array[_ScalarT] | None] | EllipsisType = None, - dtype: _nt.ToDType[_ScalarT], + dtype: _nt._ToDType[_ScalarT], **kw: Unpack[_Kwargs3], ) -> _nt.Array[_ScalarT]: ... @overload # ?d, ?d @@ -1792,7 +1792,7 @@ class _Outer2(Protocol): B: _nt.ToGeneric_nd, /, *, - dtype: _nt.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/lib/recfunctions.pyi b/src/numpy-stubs/lib/recfunctions.pyi index 31a8e14b..b862c7d2 100644 --- a/src/numpy-stubs/lib/recfunctions.pyi +++ b/src/numpy-stubs/lib/recfunctions.pyi @@ -226,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: _nt.ToDType[_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(