diff --git a/mypyc/lib-rt/int_ops.c b/mypyc/lib-rt/int_ops.c index 333783ae619d..04538ab832fc 100644 --- a/mypyc/lib-rt/int_ops.c +++ b/mypyc/lib-rt/int_ops.c @@ -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; } } @@ -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; } } @@ -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 @@ -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; } } @@ -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 @@ -567,7 +567,7 @@ 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; } } @@ -575,7 +575,7 @@ uint8_t CPyLong_AsUInt8_(PyObject *o) { } 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) { diff --git a/mypyc/test-data/run-i16.test b/mypyc/test-data/run-i16.test index fbb0c15220bc..5dd766871ebb 100644 --- a/mypyc/test-data/run-i16.test +++ b/mypyc/test-data/run-i16.test @@ -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 @@ -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: @@ -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: @@ -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: @@ -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)) diff --git a/mypyc/test-data/run-i32.test b/mypyc/test-data/run-i32.test index bb1fa43bb9fd..857279fac817 100644 --- a/mypyc/test-data/run-i32.test +++ b/mypyc/test-data/run-i32.test @@ -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 @@ -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: @@ -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: @@ -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: @@ -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)) diff --git a/mypyc/test-data/run-i64.test b/mypyc/test-data/run-i64.test index 0dcad465cc9a..d0eef23c3409 100644 --- a/mypyc/test-data/run-i64.test +++ b/mypyc/test-data/run-i64.test @@ -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: @@ -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)) @@ -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: @@ -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: @@ -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: diff --git a/mypyc/test-data/run-u8.test b/mypyc/test-data/run-u8.test index c8580f05e31c..05844de8ecff 100644 --- a/mypyc/test-data/run-u8.test +++ b/mypyc/test-data/run-u8.test @@ -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 @@ -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: @@ -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: @@ -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: @@ -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))