Skip to content

Commit 53e233a

Browse files
committed
✨ statically embed nep-50 in the numeric scalar types
1 parent c6fc320 commit 53e233a

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

src/numpy-stubs/__init__.pyi

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5090,6 +5090,10 @@ class complexfloating(inexact[_BitT1, complex], Generic[_BitT1, _BitT2]):
50905090

50915091
# NOTE: Naming it `bool_` results in less unreadable type-checker output
50925092
class bool_(generic[_BoolItemT_co], Generic[_BoolItemT_co]):
5093+
@type_check_only
5094+
def __promote__(self, to: bool_ | number, from_: bool_, /) -> bool_: ...
5095+
5096+
#
50935097
@property
50945098
@override
50955099
def itemsize(self) -> L[1]: ...
@@ -5632,6 +5636,10 @@ class _IntROpMixin(Generic[_T_co]):
56325636
def __ror__(self, x: _JustSignedInteger | _JustUnsignedInteger | _nt.Just[integer], /) -> _T_co: ...
56335637

56345638
class int8(_IntROpMixin[signedinteger], signedinteger[_n._8]): # type: ignore[misc]
5639+
@type_check_only
5640+
def __promote__(self, to: signedinteger | inexact, from_: int8 | bool_, /) -> int8: ...
5641+
5642+
#
56355643
@property
56365644
@override
56375645
def itemsize(self) -> L[1]: ...
@@ -5762,6 +5770,15 @@ class int8(_IntROpMixin[signedinteger], signedinteger[_n._8]): # type: ignore[m
57625770
def __or__(self, x: _nt.Just[_SignedIntegerT], /) -> _SignedIntegerT: ...
57635771

57645772
class uint8(unsignedinteger[_n._8]):
5773+
@type_check_only
5774+
def __promote__(
5775+
self,
5776+
to: uint8 | int16 | int32 | int64 | unsignedinteger | inexact,
5777+
from_: uint8 | bool_,
5778+
/,
5779+
) -> uint8: ...
5780+
5781+
#
57655782
@property
57665783
@override
57675784
def itemsize(self) -> L[1]: ...
@@ -6202,6 +6219,15 @@ class uint8(unsignedinteger[_n._8]):
62026219
def __ror__(self, x: _nt.Just[integer], /) -> integer: ...
62036220

62046221
class int16(_IntROpMixin[signedinteger], signedinteger[_n._16]): # type: ignore[misc]
6222+
@type_check_only
6223+
def __promote__(
6224+
self,
6225+
to: int16 | int32 | int64 | float32 | float64 | longdouble | complexfloating,
6226+
from_: int16 | uint8 | int8 | bool_,
6227+
/,
6228+
) -> int16: ...
6229+
6230+
#
62056231
@property
62066232
@override
62076233
def itemsize(self) -> L[2]: ...
@@ -6370,6 +6396,15 @@ class int16(_IntROpMixin[signedinteger], signedinteger[_n._16]): # type: ignore
63706396
def __or__(self, x: _nt.CanArray0D[int32], /) -> int32: ...
63716397

63726398
class uint16(unsignedinteger[_n._16]):
6399+
@type_check_only
6400+
def __promote__(
6401+
self,
6402+
to: uint16 | int32 | uint32 | int64 | uint64 | float32 | float64 | longdouble | complexfloating,
6403+
from_: uint16 | uint8 | bool_,
6404+
/,
6405+
) -> uint16: ...
6406+
6407+
#
63736408
@property
63746409
@override
63756410
def itemsize(self) -> L[2]: ...
@@ -6762,6 +6797,15 @@ class uint16(unsignedinteger[_n._16]):
67626797
def __ror__(self, x: _nt.Just[integer], /) -> integer: ...
67636798

67646799
class int32(_IntROpMixin[signedinteger], signedinteger[_n._32]): # type: ignore[misc]
6800+
@type_check_only
6801+
def __promote__(
6802+
self,
6803+
to: int32 | int64 | float64 | complex128 | longdouble | clongdouble,
6804+
from_: int32 | uint16 | int16 | uint8 | int8 | bool_,
6805+
/,
6806+
) -> int32: ...
6807+
6808+
#
67656809
@property
67666810
@override
67676811
def itemsize(self) -> L[4]: ...
@@ -6906,6 +6950,15 @@ class int32(_IntROpMixin[signedinteger], signedinteger[_n._32]): # type: ignore
69066950
def __or__(self, x: _nt.CanArray0D[int64], /) -> int64: ...
69076951

69086952
class uint32(unsignedinteger[_n._32]):
6953+
@type_check_only
6954+
def __promote__(
6955+
self,
6956+
to: uint32 | int64 | uint64 | float64 | complex128 | longdouble | clongdouble,
6957+
from_: uint32 | uint16 | uint8 | bool_,
6958+
/,
6959+
) -> uint32: ...
6960+
6961+
#
69096962
@property
69106963
@override
69116964
def itemsize(self) -> L[4]: ...
@@ -7202,6 +7255,15 @@ class uint32(unsignedinteger[_n._32]):
72027255
def __ror__(self, x: _nt.Just[integer], /) -> integer: ...
72037256

72047257
class int64(_IntROpMixin[int64], signedinteger[_n._64]): # type: ignore[misc]
7258+
@type_check_only
7259+
def __promote__(
7260+
self,
7261+
to: int64 | float64 | complex128 | longdouble | clongdouble,
7262+
from_: signedinteger | uint32 | uint16 | uint8 | bool_,
7263+
/,
7264+
) -> int64: ...
7265+
7266+
#
72057267
@property
72067268
@override
72077269
def itemsize(self) -> L[8]: ...
@@ -7309,6 +7371,15 @@ class int64(_IntROpMixin[int64], signedinteger[_n._64]): # type: ignore[misc]
73097371
def __or__(self, x: _JustInteger, /) -> int64: ...
73107372

73117373
class uint64(unsignedinteger[_n._64]):
7374+
@type_check_only
7375+
def __promote__(
7376+
self,
7377+
to: uint64 | float64 | complex128 | longdouble | clongdouble,
7378+
from_: unsignedinteger | bool_,
7379+
/,
7380+
) -> uint64: ...
7381+
7382+
#
73127383
@property
73137384
@override
73147385
def itemsize(self) -> L[8]: ...
@@ -7537,6 +7608,10 @@ longlong = int64
75377608
ulonglong = uint64
75387609

75397610
class float16(floating[_n._16]):
7611+
@type_check_only
7612+
def __promote__(self, to: inexact, from_: float16 | int8 | uint8 | bool_, /) -> float16: ...
7613+
7614+
#
75407615
@property
75417616
@override
75427617
def itemsize(self) -> L[2]: ...
@@ -7791,6 +7866,15 @@ class float16(floating[_n._16]):
77917866
def __rdivmod__(self, x: _JustInteger | _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
77927867

77937868
class float32(floating[_n._32]):
7869+
@type_check_only
7870+
def __promote__(
7871+
self,
7872+
to: float32 | float64 | longdouble | complexfloating,
7873+
from_: float32 | float16 | int16 | uint16 | int8 | uint8 | bool_,
7874+
/,
7875+
) -> float32: ...
7876+
7877+
#
77947878
@property
77957879
@override
77967880
def itemsize(self) -> L[4]: ...
@@ -7987,6 +8071,15 @@ class float32(floating[_n._32]):
79878071
def __rdivmod__(self, x: _JustInteger | _JustFloating | _nt.Just[inexact], /) -> _2Tuple[floating]: ... # pyright: ignore[reportIncompatibleMethodOverride]
79888072

79898073
class float64(floating[_n._64], float): # type: ignore[misc]
8074+
@type_check_only
8075+
def __promote__(
8076+
self,
8077+
to: float64 | longdouble | complex128 | clongdouble,
8078+
from_: float64 | float32 | float16 | integer | bool_,
8079+
/,
8080+
) -> float64: ...
8081+
8082+
#
79908083
def __new__(cls, x: _ConvertibleToFloat | None = 0, /) -> Self: ...
79918084
@classmethod
79928085
def __getformat__(cls, typestr: L["double", "float"], /) -> str: ...
@@ -8180,6 +8273,10 @@ single = float32
81808273
double = float64
81818274

81828275
class longdouble(floating[_n._64L]):
8276+
@type_check_only
8277+
def __promote__(self, to: longdouble | clongdouble, from_: floating | integer | bool_, /) -> longdouble: ...
8278+
8279+
#
81838280
@property
81848281
@override
81858282
def itemsize(self) -> L[12, 16]: ...
@@ -8303,6 +8400,15 @@ float96 = longdouble
83038400
float128 = longdouble
83048401

83058402
class complex64(complexfloating[_n._32]):
8403+
@type_check_only
8404+
def __promote__(
8405+
self,
8406+
to: complexfloating,
8407+
from_: complex64 | float32 | float16 | int16 | uint16 | int8 | uint8 | bool_,
8408+
/,
8409+
) -> complex64: ...
8410+
8411+
#
83068412
@property
83078413
@override
83088414
def itemsize(self) -> L[8]: ...
@@ -8426,6 +8532,15 @@ class complex64(complexfloating[_n._32]):
84268532
def __complex__(self, /) -> complex: ...
84278533

84288534
class complex128(complexfloating[_n._64], complex):
8535+
@type_check_only
8536+
def __promote__(
8537+
self,
8538+
to: complex128 | clongdouble,
8539+
from_: complex128 | complex64 | float64 | float32 | float16 | integer | bool_,
8540+
/,
8541+
) -> complex128: ...
8542+
8543+
#
84298544
@overload
84308545
def __new__(cls, real: _ConvertibleToComplex | None = 0, /) -> Self: ...
84318546
@overload
@@ -8542,6 +8657,10 @@ csingle = complex64
85428657
cdouble = complex128
85438658

85448659
class clongdouble(complexfloating[_n._64L]):
8660+
@type_check_only
8661+
def __promote__(self, to: clongdouble, from_: number | bool_, /) -> clongdouble: ...
8662+
8663+
#
85458664
@property
85468665
@override
85478666
def itemsize(self) -> L[24, 32]: ...

0 commit comments

Comments
 (0)