Skip to content

Commit 76fc161

Browse files
committed
🎨 simplify integer.__[r]sub__ using the NEP 50 embeddings
1 parent e66d618 commit 76fc161

File tree

1 file changed

+10
-243
lines changed

1 file changed

+10
-243
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 10 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,21 +4075,23 @@ class integer(_IntegralMixin, _RoundMixin, number[_BitT, int]):
40754075

40764076
# keep in sync with __add__
40774077
@overload
4078-
def __sub__(self, x: int, /) -> Self: ...
4078+
def __sub__(self, x: _nt.CanCast0D[Self] | int, /) -> Self: ...
40794079
@overload
40804080
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
40814081
@overload
4082-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ... # pyright: ignore[reportIncompatibleMethodOverride]
4082+
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
4083+
@overload
4084+
def __sub__(self, x: _nt.PromoteWith0D[Self, _ScalarT], /) -> _ScalarT: ... # pyright: ignore[reportIncompatibleMethodOverride]
40834085

4084-
# keep in sync with __radd__
4086+
#
40854087
@overload
4086-
def __rsub__(self, x: int, /) -> Self: ...
4088+
def __rsub__(self, x: _nt.CanCast0D[Self] | int, /) -> Self: ...
40874089
@overload
40884090
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
40894091
@overload
40904092
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
40914093
@overload
4092-
def __rsub__(self, x: _nt.Just[integer], /) -> integer | float64: ... # pyright: ignore[reportIncompatibleMethodOverride]
4094+
def __rsub__(self, x: _nt.PromoteWith0D[Self, _ScalarT], /) -> _ScalarT: ... # pyright: ignore[reportIncompatibleMethodOverride]
40934095

40944096
# keep in sync with __add__
40954097
@overload
@@ -4260,29 +4262,7 @@ class signedinteger(integer[_BitT]):
42604262
#
42614263
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
42624264

4263-
# keep in sync with __add__
4264-
@overload
4265-
def __sub__(self, x: _CoInt8, /) -> Self: ...
4266-
@overload
4267-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
4268-
@overload
4269-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
4270-
@overload
4271-
def __sub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
4272-
@overload
4273-
def __sub__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> signedinteger | float64: ...
4274-
4275-
# keep in sync with __radd__
4276-
@overload
4277-
def __rsub__(self, x: int, /) -> Self: ...
4278-
@overload
4279-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
4280-
@overload
4281-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
4282-
@overload
4283-
def __rsub__(self, x: _nt.Just[integer], /) -> signedinteger | float64: ...
4284-
4285-
# keep in sync with __add__
4265+
#
42864266
@overload
42874267
def __mul__(self, x: _CoInt8, /) -> Self: ...
42884268
@overload
@@ -4294,7 +4274,7 @@ class signedinteger(integer[_BitT]):
42944274
@overload
42954275
def __mul__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> signedinteger | float64: ...
42964276

4297-
# keep in sync with __radd__
4277+
#
42984278
@overload
42994279
def __rmul__(self, x: int, /) -> Self: ...
43004280
@overload
@@ -4455,32 +4435,6 @@ class unsignedinteger(integer[_BitT]):
44554435
#
44564436
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
44574437

4458-
# keep in sync with __add__
4459-
@overload
4460-
def __sub__(self, x: _CoUInt8, /) -> Self: ...
4461-
@overload
4462-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
4463-
@overload
4464-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
4465-
@overload
4466-
def __sub__(self, x: _JustUnsignedInteger, /) -> unsignedinteger: ...
4467-
@overload
4468-
def __sub__(self, x: _JustSignedInteger, /) -> signedinteger | float64: ...
4469-
@overload
4470-
def __sub__(self, x: _nt.Just[integer], /) -> integer | float64: ...
4471-
4472-
# keep in sync with __radd__
4473-
@overload
4474-
def __rsub__(self, x: int, /) -> Self: ...
4475-
@overload
4476-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
4477-
@overload
4478-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
4479-
@overload
4480-
def __rsub__(self, x: _nt.Just[integer], /) -> integer | float64: ...
4481-
@overload
4482-
def __rsub__(self, x: _JustSignedInteger, /) -> signedinteger | float64: ...
4483-
44844438
# keep in sync with __add__
44854439
@overload
44864440
def __mul__(self, x: _CoUInt8, /) -> Self: ...
@@ -5473,18 +5427,6 @@ bool = bool_
54735427

54745428
@type_check_only
54755429
class _IntROpMixin(Generic[_T_co]):
5476-
@overload
5477-
def __rsub__(self, x: int, /) -> Self: ...
5478-
@overload
5479-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
5480-
@overload
5481-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
5482-
@overload
5483-
def __rsub__(self, x: _JustSignedInteger, /) -> _T_co: ...
5484-
@overload
5485-
def __rsub__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> _T_co | float64: ...
5486-
5487-
#
54885430
@overload
54895431
def __rmul__(self, x: int, /) -> Self: ...
54905432
@overload
@@ -5589,18 +5531,6 @@ class int8(_IntROpMixin[signedinteger], signedinteger[_n._8]): # type: ignore[m
55895531
def __index__(self, /) -> int: ...
55905532
def bit_count(self, /) -> int: ...
55915533

5592-
# keep in sync with __add__
5593-
@overload
5594-
def __sub__(self, x: _CoInt8, /) -> Self: ...
5595-
@overload
5596-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
5597-
@overload
5598-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
5599-
@overload
5600-
def __sub__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> signedinteger | float64: ...
5601-
@overload
5602-
def __sub__(self, x: _nt.CanArray0D[_SignedIntegerT], /) -> _SignedIntegerT: ...
5603-
56045534
# keep in sync with __add__
56055535
@overload
56065536
def __mul__(self, x: _CoInt8, /) -> Self: ...
@@ -5725,42 +5655,6 @@ class uint8(unsignedinteger[_n._8]):
57255655
def __index__(self, /) -> int: ...
57265656
def bit_count(self, /) -> int: ...
57275657

5728-
#
5729-
@overload
5730-
def __sub__(self, x: _CoUInt8, /) -> Self: ...
5731-
@overload
5732-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
5733-
@overload
5734-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
5735-
@overload
5736-
def __sub__(self, x: _JustUnsignedInteger, /) -> unsignedinteger: ...
5737-
@overload
5738-
def __sub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
5739-
@overload
5740-
def __sub__(self, x: _nt.Just[integer], /) -> integer: ...
5741-
@overload
5742-
def __sub__(self, x: _nt.CanArray0D[_UnsignedIntegerT], /) -> _UnsignedIntegerT: ...
5743-
@overload
5744-
def __sub__(self, x: _nt.CanArray0D[int64], /) -> int64: ...
5745-
@overload
5746-
def __sub__(self, x: _nt.CanArray0D[int32], /) -> int32: ...
5747-
@overload
5748-
def __sub__(self, x: _nt.CanArray0D[_Int16m], /) -> int16: ...
5749-
5750-
#
5751-
@overload
5752-
def __rsub__(self, x: int, /) -> Self: ...
5753-
@overload
5754-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
5755-
@overload
5756-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
5757-
@overload
5758-
def __rsub__(self, x: _nt.Just[integer], /) -> integer: ...
5759-
@overload
5760-
def __rsub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
5761-
@overload
5762-
def __rsub__(self, x: _nt.CanArray0D[int8], /) -> int16: ...
5763-
57645658
#
57655659
@overload
57665660
def __mul__(self, x: _CoUInt8, /) -> Self: ...
@@ -6095,22 +5989,6 @@ class int16(_IntROpMixin[signedinteger], signedinteger[_n._16]): # type: ignore
60955989
def __index__(self, /) -> int: ...
60965990
def bit_count(self, /) -> int: ...
60975991

6098-
#
6099-
@overload
6100-
def __sub__(self, x: _CoInt16, /) -> Self: ...
6101-
@overload
6102-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
6103-
@overload
6104-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
6105-
@overload
6106-
def __sub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
6107-
@overload
6108-
def __sub__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> signedinteger | float64: ...
6109-
@overload
6110-
def __sub__(self, x: _nt.CanArray0D[int32 | uint16], /) -> int32: ...
6111-
@overload
6112-
def __sub__(self, x: _nt.CanArray0D[int64 | uint32], /) -> int64: ...
6113-
61145992
#
61155993
@overload
61165994
def __mul__(self, x: _CoInt16, /) -> Self: ...
@@ -6267,40 +6145,6 @@ class uint16(unsignedinteger[_n._16]):
62676145
def __index__(self, /) -> int: ...
62686146
def bit_count(self, /) -> int: ...
62696147

6270-
# keep in sync with __add__
6271-
@overload
6272-
def __sub__(self, x: _CoUInt16, /) -> Self: ...
6273-
@overload
6274-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
6275-
@overload
6276-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
6277-
@overload
6278-
def __sub__(self, x: _JustUnsignedInteger, /) -> unsignedinteger: ...
6279-
@overload
6280-
def __sub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
6281-
@overload
6282-
def __sub__(self, x: _nt.Just[integer], /) -> integer: ...
6283-
@overload
6284-
def __sub__(self, x: _nt.CanArray0D[_Int32m], /) -> int32: ...
6285-
@overload
6286-
def __sub__(self, x: _nt.CanArray0D[int64], /) -> int64: ...
6287-
6288-
# keep in sync with __radd__
6289-
@overload
6290-
def __rsub__(self, x: int, /) -> Self: ...
6291-
@overload
6292-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
6293-
@overload
6294-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
6295-
@overload
6296-
def __rsub__(self, x: _nt.Just[integer], /) -> integer: ...
6297-
@overload
6298-
def __rsub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
6299-
@overload
6300-
def __rsub__(self, x: _JustUnsignedInteger, /) -> unsignedinteger: ...
6301-
@overload
6302-
def __rsub__(self, x: _nt.CanArray0D[int8], /) -> int32: ...
6303-
63046148
# keep in sync with __add__
63056149
@overload
63066150
def __mul__(self, x: _CoUInt16, /) -> Self: ...
@@ -6616,20 +6460,6 @@ class int32(_IntROpMixin[signedinteger], signedinteger[_n._32]): # type: ignore
66166460
def __index__(self, /) -> int: ...
66176461
def bit_count(self, /) -> int: ...
66186462

6619-
#
6620-
@overload
6621-
def __sub__(self, x: _CoInt32, /) -> Self: ...
6622-
@overload
6623-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
6624-
@overload
6625-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
6626-
@overload
6627-
def __sub__(self, x: _JustSignedInteger, /) -> signedinteger: ...
6628-
@overload
6629-
def __sub__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> signedinteger | float64: ...
6630-
@overload
6631-
def __sub__(self, x: _nt.CanArray0D[int64 | uint32], /) -> int64: ...
6632-
66336463
#
66346464
@overload
66356465
def __mul__(self, x: _CoInt32, /) -> Self: ...
@@ -6765,35 +6595,6 @@ class uint32(unsignedinteger[_n._32]):
67656595
def __hash__(self, /) -> int: ...
67666596
def __index__(self, /) -> int: ...
67676597
def bit_count(self, /) -> int: ...
6768-
6769-
#
6770-
@overload
6771-
def __sub__(self, x: _CoUInt32, /) -> Self: ...
6772-
@overload
6773-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
6774-
@overload
6775-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
6776-
@overload
6777-
def __sub__(self, x: _JustUnsignedInteger, /) -> unsignedinteger: ...
6778-
@overload
6779-
def __sub__(self, x: _nt.CanArray0D[signedinteger] | _JustSignedInteger, /) -> int64: ...
6780-
@overload
6781-
def __sub__(self, x: _nt.Just[integer], /) -> integer: ...
6782-
6783-
#
6784-
@overload
6785-
def __rsub__(self, x: _CoUInt32, /) -> Self: ...
6786-
@overload
6787-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
6788-
@overload
6789-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
6790-
@overload
6791-
def __rsub__(self, x: _nt.Just[integer], /) -> integer: ... # type: ignore[overload-overlap]
6792-
@overload
6793-
def __rsub__(self, x: _nt.CanArray0D[signedinteger] | _JustSignedInteger, /) -> int64: ...
6794-
@overload
6795-
def __rsub__(self, x: _JustUnsignedInteger, /) -> unsignedinteger: ...
6796-
67976598
#
67986599
@overload
67996600
def __mul__(self, x: _CoUInt32, /) -> Self: ...
@@ -7055,17 +6856,7 @@ class int64(_IntROpMixin[int64], signedinteger[_n._64]): # type: ignore[misc]
70556856
def __index__(self, /) -> int: ...
70566857
def bit_count(self, /) -> int: ...
70576858

7058-
# keep in sync with __add__
7059-
@overload
7060-
def __sub__(self, x: _CoInt64, /) -> Self: ...
7061-
@overload
7062-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
7063-
@overload
7064-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
7065-
@overload
7066-
def __sub__(self, x: _nt.Just[integer] | _JustUnsignedInteger, /) -> Self | float64: ...
7067-
7068-
# keep in sync with __add__
6859+
#
70696860
@overload
70706861
def __mul__(self, x: _CoInt64, /) -> Self: ...
70716862
@overload
@@ -7173,30 +6964,6 @@ class uint64(unsignedinteger[_n._64]):
71736964
def __index__(self, /) -> int: ...
71746965
def bit_count(self, /) -> int: ...
71756966

7176-
# keep in sync with __add__
7177-
@overload
7178-
def __sub__(self, x: _CoUInt64, /) -> Self: ...
7179-
@overload
7180-
def __sub__(self, x: _nt.JustFloat, /) -> float64: ...
7181-
@overload
7182-
def __sub__(self, x: _nt.JustComplex, /) -> complex128: ...
7183-
@overload
7184-
def __sub__(self, x: _nt.CanArray0D[signedinteger] | _JustSignedInteger, /) -> float64: ...
7185-
@overload
7186-
def __sub__(self, x: _nt.Just[integer], /) -> Self | float64: ...
7187-
7188-
# keep in sync with __add__
7189-
@overload
7190-
def __rsub__(self, x: _CoUInt64, /) -> Self: ...
7191-
@overload
7192-
def __rsub__(self, x: _nt.JustFloat, /) -> float64: ...
7193-
@overload
7194-
def __rsub__(self, x: _nt.JustComplex, /) -> complex128: ...
7195-
@overload
7196-
def __rsub__(self, x: _nt.Just[integer], /) -> Self | float64: ... # type: ignore[overload-overlap]
7197-
@overload
7198-
def __rsub__(self, x: _nt.CanArray0D[signedinteger] | _JustSignedInteger, /) -> float64: ...
7199-
72006967
# keep in sync with __add__
72016968
@overload
72026969
def __mul__(self, x: _CoUInt64, /) -> Self: ...

0 commit comments

Comments
 (0)