Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit bfad574

Browse files
BUG: Add more specific integer constructors (#76)
Fixes #72 - Removed SupportsFloat from the classes int8, int16, int32, int64, uint8, uint16, uint32, and uint64 - Update tests/pass/scalars.py - Added several tests to tests/fail/scalars.py
1 parent 98959aa commit bfad574

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

Diff for: numpy-stubs/__init__.pyi

+25-8
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): ...

Diff for: tests/fail/scalars.py

+15
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,18 @@
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+
42+
class A:
43+
def __float__(self):
44+
return 1.0
45+
46+
47+
np.int8(A()) # E: incompatible type
48+
np.int16(A()) # E: incompatible type
49+
np.int32(A()) # E: incompatible type
50+
np.int64(A()) # E: incompatible type
51+
np.uint8(A()) # E: incompatible type
52+
np.uint16(A()) # E: incompatible type
53+
np.uint32(A()) # E: incompatible type
54+
np.uint64(A()) # E: incompatible type

Diff for: tests/pass/scalars.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ def __complex__(self):
77
return 3j
88

99

10+
class B:
11+
def __int__(self):
12+
return 4
13+
14+
1015
class A:
1116
def __float__(self):
12-
return 4
17+
return 4.0
1318

1419

1520
np.complex32(3)
@@ -20,7 +25,7 @@ def __float__(self):
2025
np.int16(3.4)
2126
np.int32(4)
2227
np.int64(-1)
23-
np.uint8(A())
28+
np.uint8(B())
2429
np.uint32()
2530

2631
np.float16(A())

0 commit comments

Comments
 (0)