Skip to content

Commit 5b4b3c2

Browse files
committed
🩹 remove abstract scalar __init__ methods
1 parent ec07d0a commit 5b4b3c2

2 files changed

Lines changed: 82 additions & 49 deletions

File tree

‎src/numpy-stubs/@test/static/reject/scalars.pyi‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ np.void("test") # type: ignore[call-overload] # pyright: ignore[reportArgument
3131
np.void("test", dtype=None) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue]
3232

3333
# pyright doesn't care?
34-
np.generic(1) # type: ignore[abstract]
35-
np.number(1) # type: ignore[abstract]
36-
np.integer(1) # type: ignore[abstract]
37-
np.inexact(1) # type: ignore[abstract]
38-
np.character("test") # type: ignore[abstract]
39-
np.flexible(b"test") # type: ignore[abstract]
34+
np.generic(1) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
35+
np.number(1) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
36+
np.integer(1) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
37+
np.inexact(1) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
38+
np.character("test") # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
39+
np.flexible(b"test") # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
4040

4141
np.float64(value=0.0) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
4242
np.int64(value=0) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]

‎src/numpy-stubs/__init__.pyi‎

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mypy: disable-error-code=override
2-
# ^ there are >100 false positives; we'll just rely on pyright in
2+
# ^ there are >100 false positives; we'll just rely on pyright
33

44
import ctypes as ct
55
import datetime as dt
@@ -3574,9 +3574,6 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
35743574
@property
35753575
def flat(self) -> flatiter[_nt.Array1D[Self]]: ...
35763576

3577-
#
3578-
def __init__(self, /, *args: Any, **kwargs: Any) -> None: ...
3579-
35803577
#
35813578
@overload
35823579
def __eq__(self, other: _nt.ToGeneric_0d, /) -> bool_: ...
@@ -3922,6 +3919,14 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
39223919

39233920
# NOTE: Naming it `bool_` results in less unreadable type-checker output
39243921
class bool_(generic[_BoolItemT_co], Generic[_BoolItemT_co]):
3922+
@overload
3923+
def __init__(self: _Bool0, value: L[False, 0] | _Bool0 = ..., /) -> None: ...
3924+
@overload
3925+
def __init__(self: _Bool1, value: L[True, 1] | _Bool1, /) -> None: ...
3926+
@overload
3927+
def __init__(self, value: object, /) -> None: ...
3928+
3929+
#
39253930
@property
39263931
@type_check_only
39273932
def __ctype__(self) -> ct.c_bool: ...
@@ -3955,14 +3960,6 @@ class bool_(generic[_BoolItemT_co], Generic[_BoolItemT_co]):
39553960
@override
39563961
def imag(self) -> _Bool0: ...
39573962

3958-
#
3959-
@overload
3960-
def __init__(self: _Bool0, value: L[False, 0] | _Bool0 = ..., /) -> None: ...
3961-
@overload
3962-
def __init__(self: _Bool1, value: L[True, 1] | _Bool1, /) -> None: ...
3963-
@overload
3964-
def __init__(self, value: object, /) -> None: ...
3965-
39663963
#
39673964
@override
39683965
def __hash__(self, /) -> int: ...
@@ -4393,7 +4390,6 @@ class number(_CmpOpMixin[_nt.CoComplex_0d, _nt.CoComplex_1nd], generic[_NumberIt
43934390
def itemsize(self) -> int: ...
43944391

43954392
#
4396-
def __init__(self, value: _NumberItemT_co, /) -> None: ...
43974393
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
43984394

43994395
#
@@ -4532,9 +4528,6 @@ class integer(_IntegralMixin, _RoundMixin, number[int]):
45324528
@type_check_only
45334529
def __nep50_rule5__(self, other: _JustInteger, /) -> integer | float64: ...
45344530

4535-
#
4536-
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4537-
45384531
#
45394532
@override
45404533
def __abs__(self, /) -> Self: ...
@@ -4676,6 +4669,9 @@ class signedinteger(integer):
46764669
def __nep50_rule5__(self, other: _JustInteger | _JustUnsignedInteger, /) -> signedinteger | float64: ...
46774670

46784671
class int8(_IntMixin[L[1]], signedinteger):
4672+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4673+
4674+
#
46794675
@property
46804676
@type_check_only
46814677
def __ctype__(self) -> ct.c_int8: ...
@@ -4702,6 +4698,9 @@ class int8(_IntMixin[L[1]], signedinteger):
47024698
byte = int8
47034699

47044700
class int16(_IntMixin[L[2]], signedinteger):
4701+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4702+
4703+
#
47054704
@property
47064705
@type_check_only
47074706
def __ctype__(self) -> ct.c_int16: ...
@@ -4728,6 +4727,9 @@ class int16(_IntMixin[L[2]], signedinteger):
47284727
short = int16
47294728

47304729
class int32(_IntMixin[L[4]], signedinteger):
4730+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4731+
4732+
#
47314733
@property
47324734
@type_check_only
47334735
def __ctype__(self) -> ct.c_int32: ...
@@ -4757,6 +4759,9 @@ class int32(_IntMixin[L[4]], signedinteger):
47574759
intc = int32
47584760

47594761
class int64(_IntMixin[L[8]], signedinteger):
4762+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4763+
4764+
#
47604765
@property
47614766
@type_check_only
47624767
def __ctype__(self) -> ct.c_int64: ...
@@ -4812,6 +4817,9 @@ class unsignedinteger(integer):
48124817
def __nep50_rule3__(self, other: _JustUnsignedInteger, /) -> unsignedinteger: ...
48134818

48144819
class uint8(_IntMixin[L[1]], unsignedinteger):
4820+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4821+
4822+
#
48154823
@property
48164824
@type_check_only
48174825
def __ctype__(self) -> ct.c_uint8: ...
@@ -4842,6 +4850,9 @@ class uint8(_IntMixin[L[1]], unsignedinteger):
48424850
ubyte = uint8
48434851

48444852
class uint16(_IntMixin[L[2]], unsignedinteger):
4853+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4854+
4855+
#
48454856
@property
48464857
@type_check_only
48474858
def __ctype__(self) -> ct.c_uint16: ...
@@ -4874,6 +4885,9 @@ class uint16(_IntMixin[L[2]], unsignedinteger):
48744885
ushort = uint16
48754886

48764887
class uint32(_IntMixin[L[4]], unsignedinteger):
4888+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4889+
4890+
#
48774891
@property
48784892
@type_check_only
48794893
def __ctype__(self) -> ct.c_uint32: ...
@@ -4906,6 +4920,9 @@ class uint32(_IntMixin[L[4]], unsignedinteger):
49064920
uintc = uint32
49074921

49084922
class uint64(_IntMixin[L[8]], unsignedinteger):
4923+
def __init__(self, value: _ConvertibleToInt = ..., /) -> None: ...
4924+
4925+
#
49094926
@property
49104927
@type_check_only
49114928
def __ctype__(self) -> ct.c_uint64: ...
@@ -4962,7 +4979,6 @@ class inexact(number[_InexactItemT_co], Generic[_InexactItemT_co]):
49624979
def __nep50_rule6__(self, other: _JustInexact | _JustNumber, /) -> inexact: ...
49634980

49644981
#
4965-
def __init__(self, value: _InexactItemT_co | None = ..., /) -> None: ...
49664982
@override
49674983
def __abs__(self, /) -> floating: ...
49684984

@@ -4991,8 +5007,6 @@ class floating(_RealMixin, _RoundMixin, inexact[float]):
49915007

49925008
#
49935009
@override
4994-
def __init__(self, value: _ConvertibleToFloat | None = ..., /) -> None: ...
4995-
@override
49965010
def __abs__(self, /) -> Self: ...
49975011

49985012
#
@@ -5029,6 +5043,9 @@ class floating(_RealMixin, _RoundMixin, inexact[float]):
50295043
def __rdivmod__(self, x: _nt.CastsWithScalar[Self, _FloatingT], /) -> _2Tuple[_FloatingT]: ...
50305044

50315045
class float16(_FloatMixin[L[2]], floating):
5046+
def __init__(self, value: _ConvertibleToFloat | None = ..., /) -> None: ...
5047+
5048+
#
50325049
@override
50335050
@type_check_only
50345051
def __nep50__(self, below: inexact, above: _nt.co_integer8, /) -> float16: ...
@@ -5050,6 +5067,9 @@ class float16(_FloatMixin[L[2]], floating):
50505067
half = float16
50515068

50525069
class float32(_FloatMixin[L[4]], floating):
5070+
def __init__(self, value: _ConvertibleToFloat | None = ..., /) -> None: ...
5071+
5072+
#
50535073
@property
50545074
@type_check_only
50555075
def __ctype__(self) -> ct.c_float: ...
@@ -5074,6 +5094,10 @@ class float32(_FloatMixin[L[4]], floating):
50745094
single = float32
50755095

50765096
class float64(_FloatMixin[L[8]], floating, float): # type: ignore[misc]
5097+
def __new__(cls, x: _ConvertibleToFloat | None = 0, /) -> Self: ...
5098+
def __init__(self, value: _ConvertibleToFloat | None = 0, /) -> None: ...
5099+
5100+
#
50775101
@property
50785102
@type_check_only
50795103
def __ctype__(self) -> ct.c_double: ...
@@ -5087,9 +5111,6 @@ class float64(_FloatMixin[L[8]], floating, float): # type: ignore[misc]
50875111
def __nep50_complex__(self, /) -> complex128: ...
50885112
@type_check_only
50895113
def __nep50_rule2__(self, other: complex64, /) -> complex128: ...
5090-
5091-
#
5092-
def __new__(cls, x: _ConvertibleToFloat | None = 0, /) -> Self: ...
50935114
@classmethod
50945115
def __getformat__(cls, typestr: L["double", "float"], /) -> str: ...
50955116

@@ -5115,19 +5136,17 @@ class float64(_FloatMixin[L[8]], floating, float): # type: ignore[misc]
51155136
double = float64
51165137

51175138
class longdouble(_FloatMixin[L[12, 16]], floating):
5139+
def __init__(self, value: _ConvertibleToFloat | None = ..., /) -> None: ...
5140+
5141+
#
51185142
@property
51195143
@type_check_only
51205144
def __ctype__(self) -> ct.c_longdouble: ...
51215145

51225146
#
51235147
@override
51245148
@type_check_only
5125-
def __nep50__(
5126-
self,
5127-
below: longdouble | clongdouble,
5128-
above: _nt.co_float64,
5129-
/,
5130-
) -> longdouble: ...
5149+
def __nep50__(self, below: longdouble | clongdouble, above: _nt.co_float64, /) -> longdouble: ...
51315150
@override
51325151
@type_check_only
51335152
def __nep50_complex__(self, /) -> clongdouble: ...
@@ -5177,12 +5196,6 @@ class complexfloating(inexact[complex]):
51775196
@type_check_only
51785197
def __nep50_rule6__(self, other: _JustInexact | _JustNumber, /) -> complexfloating: ...
51795198

5180-
#
5181-
@overload
5182-
def __init__(self, real: _ConvertibleToComplex | None = 0, /) -> None: ...
5183-
@overload
5184-
def __init__(self, real: _ToReal = 0, imag: _ToImag = 0, /) -> None: ...
5185-
51865199
#
51875200
@property
51885201
@override
@@ -5203,6 +5216,12 @@ class complexfloating(inexact[complex]):
52035216
def __round__(self, /, ndigits: CanIndex | None = None) -> Self: ...
52045217

52055218
class complex64(complexfloating):
5219+
@overload
5220+
def __init__(self, real: _ConvertibleToComplex | None = 0, /) -> None: ...
5221+
@overload
5222+
def __init__(self, real: _ToReal = 0, imag: _ToImag = 0, /) -> None: ...
5223+
5224+
#
52065225
@override
52075226
@type_check_only
52085227
def __nep50__(self, below: complexfloating, above: _float32_max | _nt.co_integer16, /) -> complex64: ...
@@ -5240,6 +5259,19 @@ class complex64(complexfloating):
52405259
csingle = complex64
52415260

52425261
class complex128(complexfloating, complex): # type: ignore[misc]
5262+
#
5263+
@overload
5264+
def __new__(cls, real: _ConvertibleToComplex | None = 0, /) -> Self: ...
5265+
@overload
5266+
def __new__(cls, real: _ToReal = 0, imag: _ToImag = 0, /) -> Self: ...
5267+
5268+
#
5269+
@overload
5270+
def __init__(self, real: _ConvertibleToComplex | None = 0, /) -> None: ...
5271+
@overload
5272+
def __init__(self, real: _ToReal = 0, imag: _ToImag = 0, /) -> None: ...
5273+
5274+
#
52435275
@override
52445276
@type_check_only
52455277
def __nep50__(self, below: _complex128_min, above: complex64 | _float64_max | _nt.co_integer, /) -> complex128: ...
@@ -5249,12 +5281,6 @@ class complex128(complexfloating, complex): # type: ignore[misc]
52495281
@type_check_only
52505282
def __nep50_rule2__(self, other: integer | _AbstractInteger, /) -> complex128: ...
52515283

5252-
#
5253-
@overload
5254-
def __new__(cls, real: _ConvertibleToComplex | None = 0, /) -> Self: ...
5255-
@overload
5256-
def __new__(cls, real: _ToReal = 0, imag: _ToImag = 0, /) -> Self: ...
5257-
52585284
#
52595285
@property
52605286
@override
@@ -5286,6 +5312,12 @@ class complex128(complexfloating, complex): # type: ignore[misc]
52865312
cdouble = complex128
52875313

52885314
class clongdouble(complexfloating):
5315+
@overload
5316+
def __init__(self, real: _ConvertibleToComplex | None = 0, /) -> None: ...
5317+
@overload
5318+
def __init__(self, real: _ToReal = 0, imag: _ToImag = 0, /) -> None: ...
5319+
5320+
#
52895321
@override
52905322
@type_check_only
52915323
def __nep50__(self, below: clongdouble, above: _nt.co_number, /) -> clongdouble: ...
@@ -5366,6 +5398,8 @@ class object_(_RealMixin, generic[Any]):
53665398

53675399
#
53685400
def __init__(self, value: object = ..., /) -> None: ...
5401+
5402+
#
53695403
@override
53705404
def __hash__(self, /) -> int: ...
53715405
def __abs__(self, /) -> object_: ...
@@ -5379,10 +5413,9 @@ class object_(_RealMixin, generic[Any]):
53795413
def dtype(self) -> dtypes.ObjectDType: ...
53805414

53815415
@final
5382-
class flexible(_RealMixin, generic[_FlexItemT_co], Generic[_FlexItemT_co]): ... # type: ignore[misc]
5416+
class flexible(_RealMixin, generic[_FlexItemT_co], Generic[_FlexItemT_co]): ...
53835417

5384-
class character(flexible[_CharacterItemT_co], Generic[_CharacterItemT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
5385-
def __init__(self, value: _CharacterItemT_co = ..., /) -> None: ...
5418+
class character(flexible[_CharacterItemT_co], Generic[_CharacterItemT_co]): ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
53865419

53875420
class bytes_(character[bytes], bytes): # type: ignore[misc]
53885421
@type_check_only

0 commit comments

Comments
 (0)