diff --git a/src/RestrictedPython/Limits.py b/src/RestrictedPython/Limits.py index 0da8aad..aeea4e4 100644 --- a/src/RestrictedPython/Limits.py +++ b/src/RestrictedPython/Limits.py @@ -31,7 +31,7 @@ def limited_range(iFirst, *args): if iLen < 0: iLen = 0 if iLen >= RANGELIMIT: - raise ValueError('range() too large') + raise OverflowError('To be created range() object would be to large, in RestrictedPython we only allow ' + str(RANGELIMIT) + ' elements in a range.') # NOQA: E501 return range(iStart, iEnd, iStep) diff --git a/tests/builtins/test_limits.py b/tests/builtins/test_limits.py index ac034be..20cb2e8 100644 --- a/tests/builtins/test_limits.py +++ b/tests/builtins/test_limits.py @@ -46,8 +46,9 @@ def test_limited_range_zero_step(): def test_limited_range_range_overflow(): - with pytest.raises(ValueError): + with pytest.raises(OverflowError) as excinfo: limited_range(0, 5000, 1) + assert 'To be created range() object would be to large, in RestrictedPython we only allow 1000 elements in a range.' in str(excinfo.value) # NOQA: E501 def test_limited_list_valid_list_input():