Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions mypyc/lib-rt/int_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ int64_t CPyLong_AsInt64_(PyObject *o) {
if (PyErr_Occurred()) {
return CPY_LL_INT_ERROR;
} else if (overflow) {
PyErr_SetString(PyExc_OverflowError, "int too large to convert to i64");
PyErr_SetString(PyExc_ValueError, "int too large to convert to i64");
return CPY_LL_INT_ERROR;
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ int32_t CPyLong_AsInt32_(PyObject *o) {
if (PyErr_Occurred()) {
return CPY_LL_INT_ERROR;
} else if (overflow) {
PyErr_SetString(PyExc_OverflowError, "int too large to convert to i32");
PyErr_SetString(PyExc_ValueError, "int too large to convert to i32");
return CPY_LL_INT_ERROR;
}
}
Expand Down Expand Up @@ -495,7 +495,7 @@ int32_t CPyInt32_Remainder(int32_t x, int32_t y) {
}

void CPyInt32_Overflow() {
PyErr_SetString(PyExc_OverflowError, "int too large to convert to i32");
PyErr_SetString(PyExc_ValueError, "int too large to convert to i32");
}

// i16 unboxing slow path
Expand All @@ -510,7 +510,7 @@ int16_t CPyLong_AsInt16_(PyObject *o) {
if (PyErr_Occurred()) {
return CPY_LL_INT_ERROR;
} else if (overflow) {
PyErr_SetString(PyExc_OverflowError, "int too large to convert to i16");
PyErr_SetString(PyExc_ValueError, "int too large to convert to i16");
return CPY_LL_INT_ERROR;
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ int16_t CPyInt16_Remainder(int16_t x, int16_t y) {
}

void CPyInt16_Overflow() {
PyErr_SetString(PyExc_OverflowError, "int too large to convert to i16");
PyErr_SetString(PyExc_ValueError, "int too large to convert to i16");
}

// u8 unboxing slow path
Expand All @@ -567,15 +567,15 @@ uint8_t CPyLong_AsUInt8_(PyObject *o) {
if (PyErr_Occurred()) {
return CPY_LL_UINT_ERROR;
} else if (overflow) {
PyErr_SetString(PyExc_OverflowError, "int too large or small to convert to u8");
PyErr_SetString(PyExc_ValueError, "int too large or small to convert to u8");
return CPY_LL_UINT_ERROR;
}
}
return result;
}

void CPyUInt8_Overflow() {
PyErr_SetString(PyExc_OverflowError, "int too large or small to convert to u8");
PyErr_SetString(PyExc_ValueError, "int too large or small to convert to u8");
}

double CPyTagged_TrueDivide(CPyTagged x, CPyTagged y) {
Expand Down
24 changes: 12 additions & 12 deletions mypyc/test-data/run-i16.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def test_box_and_unbox() -> None:
o2: Any = x
assert o == o2
assert x == i
with assertRaises(OverflowError, "int too large to convert to i16"):
with assertRaises(ValueError, "int too large to convert to i16"):
o = 2**15
x2: i16 = o
with assertRaises(OverflowError, "int too large to convert to i16"):
with assertRaises(ValueError, "int too large to convert to i16"):
o = -2**15 - 1
x3: i16 = o

Expand Down Expand Up @@ -209,13 +209,13 @@ def test_mixed_comparisons() -> None:

int_too_big = int() + (1 << 15)
int_too_small = int() - (1 << 15) - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i16_3 < int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_big < i16_3
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i16_3 > int_too_small
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small < i16_3

def test_mixed_arithmetic_and_bitwise_ops() -> None:
Expand All @@ -235,9 +235,9 @@ def test_mixed_arithmetic_and_bitwise_ops() -> None:

int_too_big = int() + (1 << 15)
int_too_small = int() - (1 << 15) - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i16_3 & int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small & i16_3

def test_coerce_to_and_from_int() -> None:
Expand Down Expand Up @@ -277,11 +277,11 @@ def test_explicit_conversion_overflow() -> None:
assert int(y) == min_i16

too_big = int() + 2**15
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = i16(too_big)

too_small = int() - 2**15 - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = i16(too_small)

def test_i16_from_large_small_literal() -> None:
Expand Down Expand Up @@ -320,9 +320,9 @@ def test_explicit_conversion_from_float() -> None:
assert from_float(2**15 - 1) == 2**15 - 1
assert from_float(-2**15) == -2**15
# The error message could be better, but this is acceptable
with assertRaises(OverflowError, "int too large to convert to i16"):
with assertRaises(ValueError, "int too large to convert to i16"):
assert from_float(float(2**15))
with assertRaises(OverflowError, "int too large to convert to i16"):
with assertRaises(ValueError, "int too large to convert to i16"):
# One ulp below the lowest valid i64 value
from_float(float(-2**15 - 1))

Expand Down
24 changes: 12 additions & 12 deletions mypyc/test-data/run-i32.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def test_box_and_unbox() -> None:
o2: Any = x
assert o == o2
assert x == i
with assertRaises(OverflowError, "int too large to convert to i32"):
with assertRaises(ValueError, "int too large to convert to i32"):
o = 2**31
x2: i32 = o
with assertRaises(OverflowError, "int too large to convert to i32"):
with assertRaises(ValueError, "int too large to convert to i32"):
o = -2**32 - 1
x3: i32 = o

Expand Down Expand Up @@ -209,13 +209,13 @@ def test_mixed_comparisons() -> None:

int_too_big = int() + (1 << 31)
int_too_small = int() - (1 << 31) - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i32_3 < int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_big < i32_3
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i32_3 > int_too_small
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small < i32_3

def test_mixed_arithmetic_and_bitwise_ops() -> None:
Expand All @@ -235,9 +235,9 @@ def test_mixed_arithmetic_and_bitwise_ops() -> None:

int_too_big = int() + (1 << 31)
int_too_small = int() - (1 << 31) - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i32_3 & int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small & i32_3

def test_coerce_to_and_from_int() -> None:
Expand Down Expand Up @@ -281,11 +281,11 @@ def test_explicit_conversion_overflow() -> None:
assert int(y) == min_i32

too_big = int() + 2**31
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = i32(too_big)

too_small = int() - 2**31 - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = i32(too_small)

def test_i32_from_large_small_literal() -> None:
Expand Down Expand Up @@ -318,9 +318,9 @@ def test_explicit_conversion_from_float() -> None:
assert from_float(2**31 - 1) == 2**31 - 1
assert from_float(-2**31) == -2**31
# The error message could be better, but this is acceptable
with assertRaises(OverflowError, "int too large to convert to i32"):
with assertRaises(ValueError, "int too large to convert to i32"):
assert from_float(float(2**31))
with assertRaises(OverflowError, "int too large to convert to i32"):
with assertRaises(ValueError, "int too large to convert to i32"):
# One ulp below the lowest valid i64 value
from_float(float(-2**31 - 2048))

Expand Down
24 changes: 12 additions & 12 deletions mypyc/test-data/run-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ def test_explicit_conversion_overflow() -> None:
assert int(y) == min_i64

too_big = int() + 2**63
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = i64(too_big)

too_small = int() - 2**63 - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = i64(too_small)

def test_i64_from_large_small_literal() -> None:
Expand All @@ -323,9 +323,9 @@ def test_explicit_conversion_from_float() -> None:
assert from_float(2**63 - 1024) == 2**63 - 1024
assert from_float(-2**63) == -2**63
# The error message could be better, but this is acceptable
with assertRaises(OverflowError, "int too large to convert to i64"):
with assertRaises(ValueError, "int too large to convert to i64"):
assert from_float(float(2**63))
with assertRaises(OverflowError, "int too large to convert to i64"):
with assertRaises(ValueError, "int too large to convert to i64"):
# One ulp below the lowest valid i64 value
from_float(float(-2**63 - 2048))

Expand Down Expand Up @@ -430,13 +430,13 @@ def test_mixed_comparisons() -> None:

int_too_big = int() + (1 << 63)
int_too_small = int() - (1 << 63) - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i64_3 < int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_big < i64_3
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i64_3 > int_too_small
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small < i64_3

def test_mixed_comparisons_32bit() -> None:
Expand Down Expand Up @@ -476,9 +476,9 @@ def test_mixed_arithmetic_and_bitwise_ops() -> None:

int_too_big = int() + (1 << 63)
int_too_small = int() - (1 << 63) - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert i64_3 & int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small & i64_3

def test_for_loop() -> None:
Expand Down Expand Up @@ -591,10 +591,10 @@ def test_unbox_int_fails() -> None:
with assertRaises(TypeError, msg):
x: i64 = o
o2: Any = 1 << 63
with assertRaises(OverflowError, "int too large to convert to i64"):
with assertRaises(ValueError, "int too large to convert to i64"):
y: i64 = o2
o3: Any = -(1 << 63 + 1)
with assertRaises(OverflowError, "int too large to convert to i64"):
with assertRaises(ValueError, "int too large to convert to i64"):
z: i64 = o3

class Uninit:
Expand Down
24 changes: 12 additions & 12 deletions mypyc/test-data/run-u8.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def test_box_and_unbox() -> None:
o2: Any = x
assert o == o2
assert x == i
with assertRaises(OverflowError, "int too large or small to convert to u8"):
with assertRaises(ValueError, "int too large or small to convert to u8"):
o = 256
x2: u8 = o
with assertRaises(OverflowError, "int too large or small to convert to u8"):
with assertRaises(ValueError, "int too large or small to convert to u8"):
o = -1
x3: u8 = o

Expand Down Expand Up @@ -166,13 +166,13 @@ def test_mixed_comparisons() -> None:

int_too_big = int() + 256
int_too_small = int() -1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert u8_3 < int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_big < u8_3
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert u8_3 > int_too_small
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small < u8_3

def test_mixed_arithmetic_and_bitwise_ops() -> None:
Expand All @@ -192,9 +192,9 @@ def test_mixed_arithmetic_and_bitwise_ops() -> None:

int_too_big = int() + 256
int_too_small = int() - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert u8_3 & int_too_big
with assertRaises(OverflowError):
with assertRaises(ValueError):
assert int_too_small & u8_3

def test_coerce_to_and_from_int() -> None:
Expand Down Expand Up @@ -233,11 +233,11 @@ def test_explicit_conversion_overflow() -> None:
assert int(y) == min_u8

too_big = int() + 256
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = u8(too_big)

too_small = int() - 1
with assertRaises(OverflowError):
with assertRaises(ValueError):
x = u8(too_small)

def test_u8_from_large_small_literal() -> None:
Expand Down Expand Up @@ -277,9 +277,9 @@ def test_explicit_conversion_from_float() -> None:
assert from_float(0) == 0
assert from_float(-0.999) == 0
# The error message could be better, but this is acceptable
with assertRaises(OverflowError, "int too large or small to convert to u8"):
with assertRaises(ValueError, "int too large or small to convert to u8"):
assert from_float(float(256))
with assertRaises(OverflowError, "int too large or small to convert to u8"):
with assertRaises(ValueError, "int too large or small to convert to u8"):
# One ulp below the lowest valid i64 value
from_float(float(-1.0))

Expand Down