Skip to content

Commit b77c170

Browse files
committed
[mypyc] Allow abs() on native int types
1 parent 49d0cfc commit b77c170

6 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎mypy/typeshed/stubs/mypy-extensions/mypy_extensions.pyi‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class i64:
106106
def __neg__(self) -> i64: ...
107107
def __invert__(self) -> i64: ...
108108
def __pos__(self) -> i64: ...
109+
def __abs__(self) -> i64: ...
109110
def __lt__(self, x: i64) -> bool: ...
110111
def __le__(self, x: i64) -> bool: ...
111112
def __ge__(self, x: i64) -> bool: ...
@@ -143,6 +144,7 @@ class i32:
143144
def __neg__(self) -> i32: ...
144145
def __invert__(self) -> i32: ...
145146
def __pos__(self) -> i32: ...
147+
def __abs__(self) -> i32: ...
146148
def __lt__(self, x: i32) -> bool: ...
147149
def __le__(self, x: i32) -> bool: ...
148150
def __ge__(self, x: i32) -> bool: ...
@@ -180,6 +182,7 @@ class i16:
180182
def __neg__(self) -> i16: ...
181183
def __invert__(self) -> i16: ...
182184
def __pos__(self) -> i16: ...
185+
def __abs__(self) -> i16: ...
183186
def __lt__(self, x: i16) -> bool: ...
184187
def __le__(self, x: i16) -> bool: ...
185188
def __ge__(self, x: i16) -> bool: ...
@@ -217,6 +220,7 @@ class u8:
217220
def __neg__(self) -> u8: ...
218221
def __invert__(self) -> u8: ...
219222
def __pos__(self) -> u8: ...
223+
def __abs__(self) -> u8: ...
220224
def __lt__(self, x: u8) -> bool: ...
221225
def __le__(self, x: u8) -> bool: ...
222226
def __ge__(self, x: u8) -> bool: ...

‎mypyc/test-data/run-i16.test‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def test_simple_arithmetic_ops() -> None:
121121
assert -two == -2
122122
assert -neg_one == 1
123123
assert -zero == 0
124+
assert abs(one) == 1
125+
assert abs(neg_one) == 1
126+
assert abs(zero) == 0
124127

125128
def test_bitwise_ops() -> None:
126129
x: i16 = 13855 + int()

‎mypyc/test-data/run-i32.test‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def test_simple_arithmetic_ops() -> None:
121121
assert -two == -2
122122
assert -neg_one == 1
123123
assert -zero == 0
124+
assert abs(one) == 1
125+
assert abs(neg_one) == 1
126+
assert abs(zero) == 0
124127

125128
def test_bitwise_ops() -> None:
126129
x: i32 = 1920687484 + int()

‎mypyc/test-data/run-i64.test‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ def test_simple_arithmetic_ops() -> None:
209209
assert -two == -2
210210
assert -neg_one == 1
211211
assert -zero == 0
212+
assert abs(one) == 1
213+
assert abs(neg_one) == 1
214+
assert abs(zero) == 0
212215

213216
def test_bitwise_ops() -> None:
214217
x: i64 = 7997307308812232241 + int()

‎mypyc/test-data/run-u8.test‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def test_simple_arithmetic_ops() -> None:
8282
assert -two == 254
8383
assert -neg_one == 1
8484
assert -zero == 0
85+
assert abs(one) == 1
86+
assert abs(neg_one) == 255
87+
assert abs(zero) == 0
8588

8689
def test_bitwise_ops() -> None:
8790
x: u8 = 184 + int()

‎test-data/unit/lib-stub/mypy_extensions.pyi‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class u8:
7777
def __neg__(self) -> u8: ...
7878
def __invert__(self) -> u8: ...
7979
def __pos__(self) -> u8: ...
80+
def __abs__(self) -> u8: ...
8081
def __lt__(self, x: u8) -> bool: ...
8182
def __le__(self, x: u8) -> bool: ...
8283
def __ge__(self, x: u8) -> bool: ...
@@ -107,6 +108,7 @@ class i16:
107108
def __neg__(self) -> i16: ...
108109
def __invert__(self) -> i16: ...
109110
def __pos__(self) -> i16: ...
111+
def __abs__(self) -> i16: ...
110112
def __lt__(self, x: i16) -> bool: ...
111113
def __le__(self, x: i16) -> bool: ...
112114
def __ge__(self, x: i16) -> bool: ...
@@ -137,6 +139,7 @@ class i32:
137139
def __neg__(self) -> i32: ...
138140
def __invert__(self) -> i32: ...
139141
def __pos__(self) -> i32: ...
142+
def __abs__(self) -> i32: ...
140143
def __lt__(self, x: i32) -> bool: ...
141144
def __le__(self, x: i32) -> bool: ...
142145
def __ge__(self, x: i32) -> bool: ...
@@ -167,6 +170,7 @@ class i64:
167170
def __neg__(self) -> i64: ...
168171
def __invert__(self) -> i64: ...
169172
def __pos__(self) -> i64: ...
173+
def __abs__(self) -> i64: ...
170174
def __lt__(self, x: i64) -> bool: ...
171175
def __le__(self, x: i64) -> bool: ...
172176
def __ge__(self, x: i64) -> bool: ...

0 commit comments

Comments
 (0)