Skip to content

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

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

Activity

  1. added
    docsDocumentation in the Doc dir
    3.13only security fixes
    3.14bugs and security fixes
    on May 11, 2025
  2. StanFromIreland commented on May 11, 2025

    @StanFromIreland
    Member

    "Return factorial of the nonnegative integer n."

    +1, clear as to what n should be, error should be expected otherwise.

  3. mkaraev commented on May 11, 2025

    @mkaraev
    Contributor

    I opened PR
    #133907

  4. StanFromIreland commented on May 11, 2025

    @StanFromIreland
    Member

    The pr is automatically linked, you do not need to comment it.

  5. added a commit that references this issue on May 12, 2025
  6. added a commit that references this issue on May 12, 2025
  7. added 2 commits that reference this issue on May 12, 2025
  8. skirpichev commented on May 12, 2025

    @skirpichev
    MemberAuthor

    I think, all merged.

    @mkaraev, congratulations!

  9. mkaraev commented on May 12, 2025

    @mkaraev
    Contributor

    @skirpichev @sobolevn thank you for your help :)

  10. added a commit that references this issue on Jul 12, 2025
  11. added a commit that references this issue on Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions