Skip to content

Commit 53b78d3

Browse files
authored
Merge pull request #497 from numpy/simplify-integer-binops
2 parents 97fb1da + d711487 commit 53b78d3

File tree

8 files changed

+850
-3027
lines changed

8 files changed

+850
-3027
lines changed

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@
1515
},
1616
"git.branchProtection": ["main"],
1717
"markdownlint.configFile": "docs/.markdownlint.yaml",
18-
"mypy-type-checker.path": ["uv", "run", "--no-sync", "mypy"]
18+
"mypy-type-checker.path": [
19+
"uv",
20+
"run",
21+
"--no-editable",
22+
"--no-sync",
23+
"mypy"
24+
]
1925
}

src/_numtype/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ from ._nep50 import (
5353
CanNEP50 as CanNEP50,
5454
MatchND as MatchND,
5555
PromoteWith as PromoteWith,
56+
PromoteWith0D as PromoteWith0D,
5657
)
5758
from ._scalar import (
5859
inexact32 as inexact32,

src/_numtype/_nep50.pyi

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ from typing_extensions import TypeAliasType, TypeVar
77

88
import numpy as np
99

10-
__all__ = ["CanCast0D", "CanCastND", "CanNEP50", "MatchND", "PromoteWith"]
10+
__all__ = ["CanCast0D", "CanCastND", "CanNEP50", "MatchND", "PromoteWith", "PromoteWith0D"]
1111

1212
_T_co = TypeVar("_T_co", covariant=True)
1313
_BelowT_contra = TypeVar("_BelowT_contra", bound=np.generic, contravariant=True)
14-
_AboveT_contra = TypeVar("_AboveT_contra", bound=np.generic, contravariant=True, default=Any)
14+
_AboveT_contra = TypeVar("_AboveT_contra", contravariant=True, default=Any)
1515
_OtherT_contra = TypeVar("_OtherT_contra", contravariant=True)
1616
_MatchT_co = TypeVar("_MatchT_co", bound=np.generic, covariant=True, default=Any)
1717
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
@@ -21,23 +21,46 @@ class CanNEP50(Protocol[_BelowT_contra, _AboveT_contra, _MatchT_co]):
2121
def __nep50__(self, below: _BelowT_contra, above: _AboveT_contra, /) -> _MatchT_co: ...
2222

2323
@type_check_only
24-
class _CanNEP50Int(Protocol[_OtherT_contra, _T_co]):
25-
def __nep50_int__(self, other: _OtherT_contra, /) -> _T_co: ...
24+
class _CanNEP50Rule0(Protocol[_OtherT_contra, _T_co]):
25+
def __nep50_rule0__(self, other: _OtherT_contra, /) -> _T_co: ...
2626

2727
@type_check_only
28-
class _CanNEP50Float(Protocol[_OtherT_contra, _T_co]):
29-
def __nep50_float__(self, other: _OtherT_contra, /) -> _T_co: ...
28+
class _CanNEP50Rule1(Protocol[_OtherT_contra, _T_co]):
29+
def __nep50_rule1__(self, other: _OtherT_contra, /) -> _T_co: ...
3030

3131
@type_check_only
32-
class _CanNEP50Complex(Protocol[_OtherT_contra, _T_co]):
33-
def __nep50_complex__(self, other: _OtherT_contra, /) -> _T_co: ...
32+
class _CanNEP50Rule2(Protocol[_OtherT_contra, _T_co]):
33+
def __nep50_rule2__(self, other: _OtherT_contra, /) -> _T_co: ...
34+
35+
@type_check_only
36+
class _CanNEP50Rule3(Protocol[_OtherT_contra, _T_co]):
37+
def __nep50_rule3__(self, other: _OtherT_contra, /) -> _T_co: ...
38+
39+
@type_check_only
40+
class _CanNEP50Rule4(Protocol[_OtherT_contra, _T_co]):
41+
def __nep50_rule4__(self, other: _OtherT_contra, /) -> _T_co: ...
42+
43+
@type_check_only
44+
class _CanNEP50Rule5(Protocol[_OtherT_contra, _T_co]):
45+
def __nep50_rule5__(self, other: _OtherT_contra, /) -> _T_co: ...
3446

3547
_WithT = TypeVar("_WithT")
3648
_OutT = TypeVar("_OutT", bound=np.generic)
3749

3850
PromoteWith = TypeAliasType(
3951
"PromoteWith",
40-
_CanNEP50Int[_WithT, _OutT] | _CanNEP50Float[_WithT, _OutT] | _CanNEP50Complex[_WithT, _OutT],
52+
CanNEP50[Any, _WithT, _OutT]
53+
| _CanNEP50Rule0[_WithT, _OutT]
54+
| _CanNEP50Rule1[_WithT, _OutT]
55+
| _CanNEP50Rule2[_WithT, _OutT]
56+
| _CanNEP50Rule3[_WithT, _OutT]
57+
| _CanNEP50Rule4[_WithT, _OutT]
58+
| _CanNEP50Rule5[_WithT, _OutT],
59+
type_params=(_WithT, _OutT),
60+
)
61+
PromoteWith0D = TypeAliasType(
62+
"PromoteWith0D",
63+
MatchND[tuple[()], PromoteWith[_WithT, _OutT]],
4164
type_params=(_WithT, _OutT),
4265
)
4366

src/numpy-stubs/@test/generated/scalar_ops_arithmetic.pyi

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)