Skip to content

Commit 2fac834

Browse files
authored
Merge pull request #505 from numpy/ndarray.__add__-fixes
2 parents f3ea8f6 + c63767a commit 2fac834

File tree

6 files changed

+876
-577
lines changed

6 files changed

+876
-577
lines changed

src/_numtype/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ from ._nep50 import (
5353
CastsScalar as CastsScalar,
5454
CastsWith as CastsWith,
5555
CastsWithArray as CastsWithArray,
56-
CastsWithBool as CastsWithBool,
56+
CastsWithBuiltin as CastsWithBuiltin,
5757
CastsWithComplex as CastsWithComplex,
5858
CastsWithFloat as CastsWithFloat,
5959
CastsWithInt as CastsWithInt,

src/_numtype/_nep50.pyi

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __all__ = [
1313
"CastsScalar",
1414
"CastsWith",
1515
"CastsWithArray",
16+
"CastsWithBuiltin",
1617
"CastsWithComplex",
1718
"CastsWithFloat",
1819
"CastsWithInt",
@@ -23,6 +24,9 @@ __all__ = [
2324

2425
_LikeT_co = TypeVar("_LikeT_co", covariant=True)
2526

27+
_BuitinT = TypeVar("_BuitinT")
28+
_BuitinT_co = TypeVar("_BuitinT_co", covariant=True)
29+
2630
_ScalarIn: TypeAlias = np.generic | str
2731
_ScalarInT = TypeVar("_ScalarInT", bound=_ScalarIn)
2832
_ScalarInT_contra = TypeVar("_ScalarInT_contra", bound=_ScalarIn, contravariant=True)
@@ -71,6 +75,10 @@ class _CanNEP50Rule6(Protocol[_ScalarInT_contra, _ScalarOutT_co]):
7175
def __nep50_rule6__(self, other: _ScalarInT_contra, /) -> _ScalarOutT_co: ...
7276

7377
#
78+
@type_check_only
79+
class _CanNEP50Builtin(Protocol[_BuitinT_co, _ScalarOutT_co]):
80+
def __nep50_builtin__(self, /) -> tuple[_BuitinT_co, _ScalarOutT_co]: ...
81+
7482
@type_check_only
7583
class _CanNEP50Bool(Protocol[_ScalarOutT_co]):
7684
def __nep50_bool__(self, /) -> _ScalarOutT_co: ...
@@ -161,7 +169,8 @@ CastsWithScalar = TypeAliasType(
161169
)
162170

163171
#
164-
CastsWithBool: TypeAlias = _CanNEP50Bool[_ScalarOutT]
165-
CastsWithInt: TypeAlias = _CanNEP50Int[_ScalarOutT]
166-
CastsWithFloat: TypeAlias = _CanNEP50Float[_ScalarOutT]
167-
CastsWithComplex: TypeAlias = _CanNEP50Complex[_ScalarOutT]
172+
CastsWithBuiltin: TypeAlias = _LikeNumeric[_CanNEP50Builtin[_BuitinT, _ScalarOutT], _ShapeT]
173+
CastsWithBool: TypeAlias = _LikeNumeric[_CanNEP50Bool[_ScalarOutT], _ShapeT]
174+
CastsWithInt: TypeAlias = _LikeNumeric[_CanNEP50Int[_ScalarOutT], _ShapeT]
175+
CastsWithFloat: TypeAlias = _LikeNumeric[_CanNEP50Float[_ScalarOutT], _ShapeT]
176+
CastsWithComplex: TypeAlias = _LikeNumeric[_CanNEP50Complex[_ScalarOutT], _ShapeT]

0 commit comments

Comments
 (0)