Skip to content

Commit 99ba291

Browse files
Add more specific integer constructors
Fixes numpy#72 - Removed SupportsFloat from the classes int8, int16, int32, int64, uint8, uint16, uint32, and uint64 - Removed a test from tests/pass/scalars.py - Added several tests to tests/fail/scalars.py
1 parent 98959aa commit 99ba291

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

numpy-stubs/__init__.pyi

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,18 @@ class datetime64:
417417

418418
class integer(number, _real_generic): ...
419419
class signedinteger(integer): ...
420-
class int8(signedinteger): ...
421-
class int16(signedinteger): ...
422-
class int32(signedinteger): ...
423-
class int64(signedinteger): ...
420+
421+
class int8(signedinteger):
422+
def __init__(self, value: SupportsInt = ...) -> None: ...
423+
424+
class int16(signedinteger):
425+
def __init__(self, value: SupportsInt = ...) -> None: ...
426+
427+
class int32(signedinteger):
428+
def __init__(self, value: SupportsInt = ...) -> None: ...
429+
430+
class int64(signedinteger):
431+
def __init__(self, value: SupportsInt = ...) -> None: ...
424432

425433
class timedelta64(signedinteger):
426434
def __init__(self, _data: Any = ..., _format: str = ...) -> None: ...
@@ -441,10 +449,19 @@ class timedelta64(signedinteger):
441449
def __mod__(self, other: timedelta64) -> timedelta64: ...
442450

443451
class unsignedinteger(integer): ...
444-
class uint8(unsignedinteger): ...
445-
class uint16(unsignedinteger): ...
446-
class uint32(unsignedinteger): ...
447-
class uint64(unsignedinteger): ...
452+
453+
class uint8(unsignedinteger):
454+
def __init__(self, value: SupportsInt = ...) -> None: ...
455+
456+
class uint16(unsignedinteger):
457+
def __init__(self, value: SupportsInt = ...) -> None: ...
458+
459+
class uint32(unsignedinteger):
460+
def __init__(self, value: SupportsInt = ...) -> None: ...
461+
462+
class uint64(unsignedinteger):
463+
def __init__(self, value: SupportsInt = ...) -> None: ...
464+
448465
class inexact(number): ...
449466
class floating(inexact, _real_generic): ...
450467
class float16(floating): ...

tests/fail/scalars.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,16 @@
3737
td_64 / dt_64 # E: No overload
3838
td_64 % 1 # E: Unsupported operand types
3939
td_64 % dt_64 # E: Unsupported operand types
40+
41+
class A:
42+
def __float__(self):
43+
return 1.0
44+
45+
np.int8(A()) # E: incompatible type
46+
np.int16(A()) # E: incompatible type
47+
np.int32(A()) # E: incompatible type
48+
np.int64(A()) # E: incompatible type
49+
np.uint8(A()) # E: incompatible type
50+
np.uint16(A()) # E: incompatible type
51+
np.uint32(A()) # E: incompatible type
52+
np.uint64(A()) # E: incompatible type

tests/pass/scalars.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def __float__(self):
2020
np.int16(3.4)
2121
np.int32(4)
2222
np.int64(-1)
23-
np.uint8(A())
2423
np.uint32()
2524

2625
np.float16(A())

0 commit comments

Comments
 (0)