Skip to content

Commit 2720696

Browse files
committed
🎨 simplify inexact modular binops using the NEP 50 embeddings
1 parent b848726 commit 2720696

File tree

1 file changed

+31
-203
lines changed

1 file changed

+31
-203
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 31 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ _IntScalarT = TypeVar("_IntScalarT", bound=bool_ | integer | object_)
626626
_RealNumberT = TypeVar("_RealNumberT", bound=integer | floating)
627627
_RealScalarT = TypeVar("_RealScalarT", bound=bool_ | integer | floating | object_)
628628
_IntegerT = TypeVar("_IntegerT", bound=integer)
629+
_FloatingT = TypeVar("_FloatingT", bound=floating)
629630
_ComplexFloatingT = TypeVar("_ComplexFloatingT", bound=complexfloating)
630631
_ComplexFloatingT_co = TypeVar("_ComplexFloatingT_co", bound=complexfloating, covariant=True)
631632
_InexactT = TypeVar("_InexactT", bound=inexact)
@@ -4998,62 +4999,56 @@ class inexact(number[_BitT, _InexactItemT_co], Generic[_BitT, _InexactItemT_co])
49984999
@overload
49995000
def __rtruediv__(self, x: _nt.PromoteWith0D[Self, _InexactT], /) -> _InexactT: ... # pyright: ignore[reportIncompatibleMethodOverride]
50005001

5002+
class floating(_RealMixin, _RoundMixin, inexact[_BitT, float]):
5003+
@abc.abstractmethod
5004+
@override
5005+
@type_check_only
5006+
def __nep50__(self, below: longdouble | clongdouble, above: int8 | uint8 | bool_, /) -> floating: ...
5007+
@override
5008+
@type_check_only
5009+
def __nep50_rule3__(self, other: _JustFloating, /) -> floating: ...
5010+
@override
5011+
@type_check_only
5012+
def __nep50_rule4__(self, other: _JustComplexFloating, /) -> complexfloating: ...
5013+
5014+
#
5015+
@override
5016+
def __init__(self, value: _ConvertibleToFloat | None = ..., /) -> None: ...
5017+
@override
5018+
def __abs__(self, /) -> Self: ...
5019+
50015020
#
50025021
@overload
5003-
def __floordiv__(self: inexact[Any, float], x: int | _nt.JustFloat | bool_, /) -> floating[_BitT]: ...
5022+
def __floordiv__(self, x: _nt.CanCast0D[Self] | int | _nt.JustFloat, /) -> Self: ...
50045023
@overload
5005-
def __floordiv__(self: inexact[Any, float], x: integer | _JustFloating, /) -> floating: ...
5024+
def __floordiv__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _FloatingT: ...
50065025
#
50075026
@overload
5008-
def __rfloordiv__(self: inexact[Any, float], x: int | _nt.JustFloat, /) -> floating[_BitT]: ...
5027+
def __rfloordiv__(self, x: _nt.CanCast0D[Self] | int | _nt.JustFloat, /) -> Self: ...
50095028
@overload
5010-
def __rfloordiv__(self: inexact[Any, float], x: bool_ | integer | _JustFloating, /) -> floating: ...
5011-
@overload
5012-
def __rfloordiv__(self: inexact[Any, float], x: _nt.Just[inexact], /) -> floating: ...
5029+
def __rfloordiv__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _FloatingT: ...
50135030

50145031
#
50155032
@overload
5016-
def __mod__(self: inexact[Any, float], x: int | _nt.JustFloat | bool_, /) -> floating[_BitT]: ...
5033+
def __mod__(self, x: _nt.CanCast0D[Self] | int | _nt.JustFloat, /) -> Self: ...
50175034
@overload
5018-
def __mod__(self: inexact[Any, float], x: integer | _JustFloating, /) -> floating: ...
5035+
def __mod__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _FloatingT: ...
50195036
#
50205037
@overload
5021-
def __rmod__(self: inexact[Any, float], x: int | _nt.JustFloat, /) -> floating[_BitT]: ...
5022-
@overload
5023-
def __rmod__(self: inexact[Any, float], x: bool_ | integer | _JustFloating, /) -> floating: ...
5038+
def __rmod__(self, x: _nt.CanCast0D[Self] | int | _nt.JustFloat, /) -> Self: ...
50245039
@overload
5025-
def __rmod__(self: inexact[Any, float], x: _nt.Just[inexact], /) -> floating: ...
5040+
def __rmod__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _FloatingT: ...
50265041

50275042
#
50285043
@overload
5029-
def __divmod__(self: inexact[Any, float], x: int | _nt.JustFloat | bool_, /) -> _2Tuple[floating[_BitT]]: ...
5044+
def __divmod__(self, x: _nt.CanCast0D[Self] | int | _nt.JustFloat, /) -> _2Tuple[Self]: ...
50305045
@overload
5031-
def __divmod__(self: inexact[Any, float], x: integer | _JustFloating, /) -> _2Tuple[floating]: ...
5046+
def __divmod__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _2Tuple[_FloatingT]: ...
50325047
#
50335048
@overload
5034-
def __rdivmod__(self: inexact[Any, float], x: int | _nt.JustFloat, /) -> _2Tuple[floating[_BitT]]: ...
5035-
@overload
5036-
def __rdivmod__(self: inexact[Any, float], x: bool_ | integer | _JustFloating, /) -> _2Tuple[floating]: ...
5049+
def __rdivmod__(self, x: _nt.CanCast0D[Self] | int | _nt.JustFloat, /) -> _2Tuple[Self]: ...
50375050
@overload
5038-
def __rdivmod__(self: inexact[Any, float], x: _nt.Just[inexact], /) -> _2Tuple[floating]: ...
5039-
5040-
class floating(_RealMixin, _RoundMixin, inexact[_BitT, float]):
5041-
@abc.abstractmethod
5042-
@override
5043-
@type_check_only
5044-
def __nep50__(self, below: longdouble | clongdouble, above: int8 | uint8 | bool_, /) -> floating: ...
5045-
@override
5046-
@type_check_only
5047-
def __nep50_rule3__(self, other: _JustFloating, /) -> floating: ...
5048-
@override
5049-
@type_check_only
5050-
def __nep50_rule4__(self, other: _JustComplexFloating, /) -> complexfloating: ...
5051-
5052-
#
5053-
@override
5054-
def __init__(self, value: _ConvertibleToFloat | None = ..., /) -> None: ...
5055-
@override
5056-
def __abs__(self, /) -> Self: ...
5051+
def __rdivmod__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _2Tuple[_FloatingT]: ...
50575052

50585053
class float16(floating[_n._16]):
50595054
@override
@@ -5083,63 +5078,6 @@ class float16(floating[_n._16]):
50835078
def is_integer(self, /) -> py_bool: ...
50845079
def as_integer_ratio(self, /) -> tuple[int, int]: ...
50855080

5086-
#
5087-
@overload
5088-
def __floordiv__(self, x: _CoFloat16, /) -> Self: ...
5089-
@overload
5090-
def __floordiv__(self, x: _nt.CanArray0D[_nt.integer16], /) -> float32: ...
5091-
@overload
5092-
def __floordiv__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5093-
@overload
5094-
def __floordiv__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5095-
#
5096-
@overload
5097-
def __rfloordiv__(self, x: _CoFloat16, /) -> Self: ...
5098-
@overload
5099-
def __rfloordiv__(self, x: _nt.CanArray0D[_nt.integer16], /) -> float32: ...
5100-
@overload
5101-
def __rfloordiv__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5102-
@overload
5103-
def __rfloordiv__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5104-
5105-
#
5106-
@overload
5107-
def __mod__(self, x: _CoFloat16, /) -> Self: ...
5108-
@overload
5109-
def __mod__(self, x: _nt.CanArray0D[_nt.integer16], /) -> float32: ...
5110-
@overload
5111-
def __mod__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5112-
@overload
5113-
def __mod__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5114-
#
5115-
@overload
5116-
def __rmod__(self, x: _CoFloat16, /) -> Self: ...
5117-
@overload
5118-
def __rmod__(self, x: _nt.CanArray0D[_nt.integer16], /) -> float32: ...
5119-
@overload
5120-
def __rmod__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5121-
@overload
5122-
def __rmod__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5123-
5124-
#
5125-
@overload
5126-
def __divmod__(self, x: _CoFloat16, /) -> _2Tuple[Self]: ...
5127-
@overload
5128-
def __divmod__(self, x: _nt.CanArray0D[_nt.integer16], /) -> _2Tuple[float32]: ...
5129-
@overload
5130-
def __divmod__(self, x: _nt.CanArray0D[_Integer32p], /) -> _2Tuple[float64]: ...
5131-
@overload
5132-
def __divmod__(self, x: _JustInteger | _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
5133-
#
5134-
@overload
5135-
def __rdivmod__(self, x: _CoFloat16, /) -> _2Tuple[Self]: ...
5136-
@overload
5137-
def __rdivmod__(self, x: _nt.CanArray0D[_nt.integer16], /) -> _2Tuple[float32]: ...
5138-
@overload
5139-
def __rdivmod__(self, x: _nt.CanArray0D[_Integer32p], /) -> _2Tuple[float64]: ...
5140-
@overload
5141-
def __rdivmod__(self, x: _JustInteger | _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
5142-
51435081
half = float16
51445082

51455083
class float32(floating[_n._32]):
@@ -5173,51 +5111,6 @@ class float32(floating[_n._32]):
51735111
def is_integer(self, /) -> py_bool: ...
51745112
def as_integer_ratio(self, /) -> tuple[int, int]: ...
51755113

5176-
#
5177-
@overload
5178-
def __floordiv__(self, x: _CoFloat32, /) -> Self: ...
5179-
@overload
5180-
def __floordiv__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5181-
@overload
5182-
def __floordiv__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5183-
#
5184-
@overload
5185-
def __rfloordiv__(self, x: _CoFloat32, /) -> Self: ...
5186-
@overload
5187-
def __rfloordiv__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5188-
@overload
5189-
def __rfloordiv__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5190-
5191-
#
5192-
@overload
5193-
def __mod__(self, x: _CoFloat32, /) -> Self: ...
5194-
@overload
5195-
def __mod__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5196-
@overload
5197-
def __mod__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5198-
#
5199-
@overload
5200-
def __rmod__(self, x: _CoFloat32, /) -> Self: ...
5201-
@overload
5202-
def __rmod__(self, x: _nt.CanArray0D[_Integer32p], /) -> float64: ...
5203-
@overload
5204-
def __rmod__(self, x: _nt.ToInteger_0d | _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5205-
5206-
#
5207-
@overload
5208-
def __divmod__(self, x: _CoFloat32, /) -> _2Tuple[Self]: ...
5209-
@overload
5210-
def __divmod__(self, x: _nt.CanArray0D[_Integer32p], /) -> _2Tuple[float64]: ...
5211-
@overload
5212-
def __divmod__(self, x: _JustInteger | _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
5213-
#
5214-
@overload
5215-
def __rdivmod__(self, x: _CoFloat32, /) -> _2Tuple[Self]: ...
5216-
@overload
5217-
def __rdivmod__(self, x: _nt.CanArray0D[_Integer32p], /) -> _2Tuple[float64]: ...
5218-
@overload
5219-
def __rdivmod__(self, x: _JustInteger | _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
5220-
52215114
single = float32
52225115

52235116
class float64(floating[_n._64], float): # type: ignore[misc]
@@ -5266,39 +5159,6 @@ class float64(floating[_n._64], float): # type: ignore[misc]
52665159
@override
52675160
def as_integer_ratio(self, /) -> tuple[int, int]: ...
52685161

5269-
#
5270-
@overload
5271-
def __floordiv__(self, x: _CoFloat64, /) -> Self: ...
5272-
@overload
5273-
def __floordiv__(self, x: _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5274-
#
5275-
@overload
5276-
def __rfloordiv__(self, x: _CoFloat64, /) -> Self: ...
5277-
@overload
5278-
def __rfloordiv__(self, x: _JustFloating | _nt.Just[inexact], /) -> floating: ...
5279-
5280-
#
5281-
@overload
5282-
def __mod__(self, x: _CoFloat64, /) -> Self: ...
5283-
@overload
5284-
def __mod__(self, x: _JustFloating | _nt.Just[inexact], /) -> floating: ... # pyright: ignore[reportIncompatibleMethodOverride]
5285-
#
5286-
@overload
5287-
def __rmod__(self, x: _CoFloat64, /) -> Self: ...
5288-
@overload
5289-
def __rmod__(self, x: _JustFloating | _nt.Just[inexact], /) -> floating: ...
5290-
5291-
#
5292-
@overload
5293-
def __divmod__(self, x: _nt.CoFloat64_0d, /) -> _2Tuple[Self]: ...
5294-
@overload
5295-
def __divmod__(self, x: _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
5296-
#
5297-
@overload
5298-
def __rdivmod__(self, x: _nt.CoFloat64_0d, /) -> _2Tuple[Self]: ...
5299-
@overload
5300-
def __rdivmod__(self, x: _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
5301-
53025162
double = float64
53035163

53045164
class longdouble(floating[_n._64L]):
@@ -5342,24 +5202,6 @@ class longdouble(floating[_n._64L]):
53425202
@override
53435203
def tolist(self, /) -> Self: ... # pyright: ignore[reportIncompatibleMethodOverride]
53445204

5345-
#
5346-
@override
5347-
def __floordiv__(self, x: _nt.CoFloating_0d | _JustFloating | _nt.Just[inexact] | _nt.JustFloat, /) -> Self: ...
5348-
@override
5349-
def __rfloordiv__(self, x: _nt.CoFloating_0d | _JustFloating | _nt.Just[inexact] | _nt.JustFloat, /) -> Self: ...
5350-
5351-
#
5352-
@override
5353-
def __mod__(self, x: _nt.CoFloating_0d | _JustFloating | _nt.Just[inexact] | _nt.JustFloat, /) -> Self: ...
5354-
@override
5355-
def __rmod__(self, x: _nt.CoFloating_0d | _JustFloating | _nt.Just[inexact] | _nt.JustFloat, /) -> Self: ...
5356-
5357-
#
5358-
@override
5359-
def __divmod__(self, x: _nt.CoFloating_0d | _JustFloating | _nt.Just[inexact] | _nt.JustFloat, /) -> _2Tuple[Self]: ...
5360-
@override
5361-
def __rdivmod__(self, x: _nt.CoFloating_0d | _JustFloating | _nt.Just[inexact] | _nt.JustFloat, /) -> _2Tuple[Self]: ...
5362-
53635205
float96 = longdouble
53645206
float128 = longdouble
53655207

@@ -5410,20 +5252,6 @@ class complexfloating(inexact[_BitT1, complex], Generic[_BitT1, _BitT2]):
54105252
@override
54115253
def __abs__(self, /) -> floating: ...
54125254

5413-
# NOTE: Without these mypy will `[misc]` instead of `[opererator]`
5414-
@override
5415-
def __floordiv__(self, x: Never, /) -> Never: ... # pyright: ignore[reportIncompatibleMethodOverride]
5416-
@override
5417-
def __rfloordiv__(self, x: Never, /) -> Never: ... # pyright: ignore[reportIncompatibleMethodOverride]
5418-
@override
5419-
def __mod__(self, x: Never, /) -> Never: ... # pyright: ignore[reportIncompatibleMethodOverride]
5420-
@override
5421-
def __rmod__(self, x: Never, /) -> Never: ... # pyright: ignore[reportIncompatibleMethodOverride]
5422-
@override
5423-
def __divmod__(self, x: Never, /) -> Never: ... # pyright: ignore[reportIncompatibleMethodOverride]
5424-
@override
5425-
def __rdivmod__(self, x: Never, /) -> Never: ... # pyright: ignore[reportIncompatibleMethodOverride]
5426-
54275255
#
54285256
@deprecated("The Python built-in `round` is deprecated for complex scalars, and will raise a `TypeError` in a future release")
54295257
def __round__(self, /, ndigits: CanIndex | None = None) -> Self: ...

0 commit comments

Comments
 (0)