New submission from Serhiy Storchaka:

OverflowError usually is caused by platform limitations. It is raised on the 
fence between Python and C when convert Python integer to C integer type. On 
other platform the same input can be accepted or cause raising ValueError if 
the value is out of range.

I think we should avoid raising OverflowError if possible. If the function 
accepts only non-negative integers, it should raise the same ValueError, 
IndexError or OverflowError for -10**100 as for -1. If the function bounds 
integer value to the range from 0 to 100, it should do this also for integers 
that don't fit in C integer type. If large argument means allocating an amount 
of memory that exceeds the address space, it should raise MemoryError rather 
than OverflowError.

This principle is already supported in the part of the interpreter. For example:

>>> 'abc'[:10**100]
'abc'
>>> 'abc'[-10**100:]
'abc'
>>> bytes([10**100])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: bytes must be in range(0, 256)
>>> round(1.2, 10**100)
1.2
>>> round(1.2, -10**100)
0.0
>>> math.factorial(-10**100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: factorial() not defined for negative values

This is a meta-issue. Concrete changes will be made in sub-issues.

----------
components: Interpreter Core
messages: 289747
nosy: Oren Milman, haypo, mark.dickinson, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Avoid raising OverflowError if possible
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29833>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to