Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC502 Raises section in response to assert #213

Open
pechersky opened this issue Feb 6, 2025 · 1 comment · May be fixed by #215
Open

DOC502 Raises section in response to assert #213

pechersky opened this issue Feb 6, 2025 · 1 comment · May be fixed by #215

Comments

@pechersky
Copy link

pechersky commented Feb 6, 2025

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?

@jsh9
Copy link
Owner

jsh9 commented Feb 6, 2025

I think this is a good suggestion. My bandwidth is a bit limited at this moment, so would you be willing to make a code change?

The logic of reporting DOC502 is here:

if not hasRaiseStmt and docstringHasRaisesSection:
if not self.isAbstractMethod:
violations.append(v502)

(v502 means "Violation 502" and hence DOC502)

Thanks!

pechersky added a commit to pechersky/pydoclint that referenced this issue Feb 6, 2025
Should the language of DOC5* be modified to include assert?
Should it be a new DOC rule?

Closes jsh9#213.
@pechersky pechersky linked a pull request Feb 6, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants