Should the docstring only contain the exceptions that are explicitly raised by a function?

前端 未结 2 1173
别那么骄傲
别那么骄傲 2021-02-20 15:36

When writing doc strings in python, I am wondering if the docstring should contain the exceptions that are implicitly raised or if it should also contain the exceptions I explic

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 15:53

    No. The docstring should describe the input expected. If this were my function, I would include something like this in the docstring:

    """Return the inverse of an integer.  ZeroDivisionError is raised if zero is
    passed to this function."""
    

    Therefore it is specified that the input should be an integer. Specifying that the function can raise a TypeError just overly complicates the docstring.

提交回复
热议问题