This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Oren Milman, mark.dickinson, rhettinger, serhiy.storchaka, vstinner
Date 2017-03-17.08:31:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1489739461.89.0.615647789001.issue29833@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-03-17 08:31:01serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, mark.dickinson, vstinner, Oren Milman
2017-03-17 08:31:01serhiy.storchakasetmessageid: <1489739461.89.0.615647789001.issue29833@psf.upfronthosting.co.za>
2017-03-17 08:31:01serhiy.storchakalinkissue29833 messages
2017-03-17 08:31:01serhiy.storchakacreate