Josh Rosenberg added the comment:

I just think it's a little odd to make math.factorial uniquely sensitive to the 
documented definition of OverflowError. Basically every one of the non-masking 
PyLong_As<CType> interfaces uses OverflowError for too large values.

In fact, all the functions which are converting to unsigned C types and aren't 
doing so for "program logic reasons" (e.g. the shift functions don't accept a 
negative shift due to semantic obscurity, and long_to_bytes doesn't accept a 
negative length for the output) use OverflowError when a negative value is 
passed as well.

The PyArg_ParseTuple* functions raise OverflowError as well, either implicitly 
(when they call a PyLong_As<CType> function), or explicitly for those functions 
that impose more restrictive ranges than the PyLong function they wrap.

Long story short: The majority of C extension functions that convert to C level 
types are raising OverflowError to mean "out of range for implementation's 
chosen C type" (whether too large, too small, or negative when only unsigned 
values excepted) as a side-effect of using Python's documented APIs. Making 
math.factorial the exception would be violating the reasonable expectation one 
might get from using similar functions.

----------

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

Reply via email to