Inaccuracy in the description of factorial function
Documentation of math.factorial function says [1]:
Raises ValueError if x is not integral or is negative.
It should be changed to:
Raises ValueError if x is negative or TypeError if it is not integral.
It's applicable for Python versions 2.7 and 3.4. I didn't check it for other versions. Doc/library/math.rst file. Thanks [1] https://docs.python.org/3/library/math.html#math.factorial
Hi Sergey,
On Sat, Dec 27, 2014 at 12:51 PM, Sergey Skovorodkin
Documentation of math.factorial function says [1]:
Raises ValueError if x is not integral or is negative.
It should be changed to:
Raises ValueError if x is negative or TypeError if it is not integral.
It's applicable for Python versions 2.7 and 3.4. I didn't check it for other versions.
Thanks for the report, but I don't think any change should be made. See below:
math.factorial(-3) # negative x Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: factorial() not defined for negative values math.factorial(3.14) # non-integral x Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: factorial() only accepts integral values math.factorial('nope') # non-number x Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: an integer is required (got type str)
The TypeError raised in the non-number x case is just like the TypeError that any function might raise if it receives an argument of the wrong type. We generally don't document places that could raise TypeError because nearly any function could, and a TypeError generally indicates a programming error rather than something that can (or should) be recovered from. Regards, -- Zach
participants (2)
-
Sergey Skovorodkin
-
Zachary Ware