Skip to content

Invalid error type in math.factorial sphinx docs/docstring #133904

Closed
@skirpichev

Description

@skirpichev

Documentation says: Raises ValueError if n is not integral or is negative.
Docstring: Raise a ValueError if x is negative or non-integral.

State of art:

>>> math.factorial(1.0)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    math.factorial(1.0)
    ~~~~~~~~~~~~~~^^^^^
TypeError: 'float' object cannot be interpreted as an integer
>>> math.factorial(-1.0)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    math.factorial(-1.0)
    ~~~~~~~~~~~~~~^^^^^^
TypeError: 'float' object cannot be interpreted as an integer
>>> math.factorial(-1)
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    math.factorial(-1)
    ~~~~~~~~~~~~~~^^^^
ValueError: factorial() not defined for negative values

Documentation should be fixed to state, that TypeError is raised for non-integral arguments.

Or just omit description of exceptions and reduce docs to: "Return factorial of the nonnegative integer n."

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesdocsDocumentation in the Doc direasy

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions