Skip to content

Commit fff5c9c

Browse files
committed
🎨 DRY concrete floating subtype common properties and methods
1 parent 9e19755 commit fff5c9c

File tree

1 file changed

+19
-56
lines changed

1 file changed

+19
-56
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,7 +5050,22 @@ class floating(_RealMixin, _RoundMixin, inexact[_BitT, float]):
50505050
@overload
50515051
def __rdivmod__(self, x: _nt.PromoteWith0D[Self, _FloatingT], /) -> _2Tuple[_FloatingT]: ...
50525052

5053-
class float16(floating[_n._16]):
5053+
_FloatSizeT_co = TypeVar("_FloatSizeT_co", bound=L[2, 4, 8, 12, 16], covariant=True)
5054+
5055+
@type_check_only
5056+
class _FloatMixin(Generic[_FloatSizeT_co]):
5057+
@property
5058+
def itemsize(self) -> _FloatSizeT_co: ...
5059+
@property
5060+
def nbytes(self) -> _FloatSizeT_co: ...
5061+
5062+
#
5063+
@override
5064+
def __hash__(self, /) -> int: ...
5065+
def is_integer(self, /) -> py_bool: ...
5066+
def as_integer_ratio(self, /) -> tuple[int, int]: ...
5067+
5068+
class float16(_FloatMixin[L[2]], floating[_n._16]):
50545069
@override
50555070
@type_check_only
50565071
def __nep50__(self, below: inexact, above: int8 | uint8 | bool_, /) -> float16: ...
@@ -5064,23 +5079,9 @@ class float16(floating[_n._16]):
50645079
@type_check_only
50655080
def __nep50_rule2__(self, other: _JustInteger, /) -> floating: ...
50665081

5067-
#
5068-
@property
5069-
@override
5070-
def itemsize(self) -> L[2]: ...
5071-
@property
5072-
@override
5073-
def nbytes(self) -> L[2]: ...
5074-
5075-
#
5076-
@override
5077-
def __hash__(self, /) -> int: ...
5078-
def is_integer(self, /) -> py_bool: ...
5079-
def as_integer_ratio(self, /) -> tuple[int, int]: ...
5080-
50815082
half = float16
50825083

5083-
class float32(floating[_n._32]):
5084+
class float32(_FloatMixin[L[4]], floating[_n._32]):
50845085
@override
50855086
@type_check_only
50865087
def __nep50__(
@@ -5097,23 +5098,9 @@ class float32(floating[_n._32]):
50975098
@type_check_only
50985099
def __nep50_rule2__(self, other: _JustInteger, /) -> floating: ...
50995100

5100-
#
5101-
@property
5102-
@override
5103-
def itemsize(self) -> L[4]: ...
5104-
@property
5105-
@override
5106-
def nbytes(self) -> L[4]: ...
5107-
5108-
#
5109-
@override
5110-
def __hash__(self, /) -> int: ...
5111-
def is_integer(self, /) -> py_bool: ...
5112-
def as_integer_ratio(self, /) -> tuple[int, int]: ...
5113-
51145101
single = float32
51155102

5116-
class float64(floating[_n._64], float): # type: ignore[misc]
5103+
class float64(_FloatMixin[L[8]], floating[_n._64], float): # type: ignore[misc]
51175104
@override
51185105
@type_check_only
51195106
def __nep50__(
@@ -5136,12 +5123,6 @@ class float64(floating[_n._64], float): # type: ignore[misc]
51365123
#
51375124
@property
51385125
@override
5139-
def itemsize(self) -> L[8]: ...
5140-
@property
5141-
@override
5142-
def nbytes(self) -> L[8]: ...
5143-
@property
5144-
@override
51455126
def real(self) -> Self: ...
51465127
@property
51475128
@override
@@ -5154,14 +5135,10 @@ class float64(floating[_n._64], float): # type: ignore[misc]
51545135
def __abs__(self, /) -> float64: ...
51555136
@override
51565137
def conjugate(self) -> Self: ...
5157-
@override
5158-
def is_integer(self, /) -> py_bool: ...
5159-
@override
5160-
def as_integer_ratio(self, /) -> tuple[int, int]: ...
51615138

51625139
double = float64
51635140

5164-
class longdouble(floating[_n._64L]):
5141+
class longdouble(_FloatMixin[L[12, 16]], floating[_n._64L]):
51655142
@override
51665143
@type_check_only
51675144
def __nep50__(
@@ -5180,20 +5157,6 @@ class longdouble(floating[_n._64L]):
51805157
@type_check_only
51815158
def __nep50_rule4__(self, other: complexfloating | _JustComplexFloating, /) -> clongdouble: ...
51825159

5183-
#
5184-
@property
5185-
@override
5186-
def itemsize(self) -> L[12, 16]: ...
5187-
@property
5188-
@override
5189-
def nbytes(self) -> L[12, 16]: ...
5190-
5191-
#
5192-
@override
5193-
def __hash__(self, /) -> int: ...
5194-
def is_integer(self, /) -> py_bool: ...
5195-
def as_integer_ratio(self, /) -> tuple[int, int]: ...
5196-
51975160
#
51985161
@overload
51995162
def item(self, /) -> Self: ...

0 commit comments

Comments
 (0)