Skip to content

Commit b0c37b8

Browse files
author
Bas van Beek
committed
TST: Update the typing tests for np.number subclasses
1 parent 85841fc commit b0c37b8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

numpy/typing/tests/data/fail/scalars.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import sys
12
import numpy as np
23

34
f2: np.float16
45
f8: np.float64
6+
c8: np.complex64
57

68
# Construction
79

@@ -80,3 +82,13 @@ def func(a: np.float32) -> None: ...
8082

8183
func(f2) # E: incompatible type
8284
func(f8) # E: incompatible type
85+
86+
round(c8) # E: No overload variant
87+
88+
c8.__getnewargs__() # E: Invalid self argument
89+
f2.__getnewargs__() # E: Invalid self argument
90+
f2.is_integer() # E: Invalid self argument
91+
f2.hex() # E: Invalid self argument
92+
np.float16.fromhex("0x0.0p+0") # E: Invalid self argument
93+
f2.__trunc__() # E: Invalid self argument
94+
f2.__getformat__("float") # E: Invalid self argument

numpy/typing/tests/data/reveal/scalars.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import numpy as np
23

34
b: np.bool_
@@ -6,6 +7,7 @@
67
f8: np.float64
78
c8: np.complex64
89
c16: np.complex128
10+
m: np.timedelta64
911
U: np.str_
1012
S: np.bytes_
1113

@@ -126,3 +128,31 @@
126128
reveal_type(i8.getfield(float)) # E: Any
127129
reveal_type(i8.getfield(np.float64)) # E: {float64}
128130
reveal_type(i8.getfield(np.float64, 8)) # E: {float64}
131+
132+
reveal_type(f8.as_integer_ratio()) # E: Tuple[builtins.int, builtins.int]
133+
reveal_type(f8.is_integer()) # E: bool
134+
reveal_type(f8.__trunc__()) # E: int
135+
reveal_type(f8.__getformat__("float")) # E: str
136+
reveal_type(f8.hex()) # E: str
137+
reveal_type(np.float64.fromhex("0x0.0p+0")) # E: {float64}
138+
139+
reveal_type(f8.__getnewargs__()) # E: Tuple[builtins.float]
140+
reveal_type(c16.__getnewargs__()) # E: Tuple[builtins.float, builtins.float]
141+
142+
reveal_type(i8.numerator) # E: {int64}
143+
reveal_type(i8.denominator) # E: Literal[1]
144+
reveal_type(u8.numerator) # E: {uint64}
145+
reveal_type(u8.denominator) # E: Literal[1]
146+
reveal_type(m.numerator) # E: numpy.timedelta64
147+
reveal_type(m.denominator) # E: Literal[1]
148+
149+
reveal_type(round(i8)) # E: int
150+
reveal_type(round(i8, 3)) # E: {int64}
151+
reveal_type(round(u8)) # E: int
152+
reveal_type(round(u8, 3)) # E: {uint64}
153+
reveal_type(round(f8)) # E: int
154+
reveal_type(round(f8, 3)) # E: {float64}
155+
156+
if sys.version_info >= (3, 9):
157+
reveal_type(f8.__ceil__()) # E: int
158+
reveal_type(f8.__floor__()) # E: int

0 commit comments

Comments
 (0)