Skip to content

DOC502 Raises section in response to assert #213

@pechersky

Description

@pechersky

DOC502 gets flagged in function docstrings where the function body has an assert condition, error_msg style, saying that there are no raise statements.

Consider the following file

def raises_assert() -> None:
    """Raises an AssertionError.
    
    Raises:
        AssertionError: foo.
    """
    assert False, "foo"

raises_assert()

When ran:

$ python assert_mwe.py
Traceback (most recent call last):
  File "/home/user/assert_mwe.py", line 9, in <module>
    raises_assert()
  File "/home/user/assert_mwe.py", line 7, in raises_assert
    assert False, "foo"
AssertionError: foo

And pydoclint complains about the file:

$  pydoclint assert_mwe.py 
assert_mwe.py
assert_mwe.py
    1: DOC502: Function `raises_assert` has a "Raises" section in the docstring, but there are not "raise" statements in the body

Could the codepath that checks for these support AssertionError when assert is found?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions