[docs] [issue21559] OverflowError should not happen for integer operations

Terry J. Reedy report at bugs.python.org
Mon Jun 2 20:02:12 CEST 2014


Terry J. Reedy added the comment:

I was tempted to close this, but I think there is an issue that 'theme' has implied but not stated clearly enough. The OverflowError entry might be re-written as "Raised when the result of an arithmetic operation involving at least one non-int is too large to be represented. For pairs of ints, MemoryError is raised instead." This much is true. However, the clear implication is that a binary operation on non-ints is the only situation in which OverflowError is raised. But as theme has shown, it is not. In this sense, the doc is incomplete.

Another, unstated, situation is failure of an internal conversion from an int to an internal type. In #20539, #20539, the justification for switching from MemoryError to OverflowError when factorial input grows too large for conversion is that memory is then not filled. In #21444, the justification is history.

A third possibility is that OverflowError is used instead of ValueError when an int fails a simple range check. See #15988: _testcapi.getargs_b requires an int in range(256). -1 and 256 raise OverflowErrors. #7267 is about the same issue. An int not being in range(256) has nothing to do with the merging of integer types in 3.x.

So I think that the docs need a new sentence. Both alternatives can be summarized by "OverflowError may also be raised for integers that are outside a required range." Knowing this might help people debugging such situations.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21559>
_______________________________________


More information about the docs mailing list