Message289747
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. |
|
Date |
User |
Action |
Args |
2017-03-17 08:31:01 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, mark.dickinson, vstinner, Oren Milman |
2017-03-17 08:31:01 | serhiy.storchaka | set | messageid: <1489739461.89.0.615647789001.issue29833@psf.upfronthosting.co.za> |
2017-03-17 08:31:01 | serhiy.storchaka | link | issue29833 messages |
2017-03-17 08:31:01 | serhiy.storchaka | create | |
|