Skip to content

DOC501 False Positive #12647

@will-schneble

Description

@will-schneble

Describe the bug
DOC501 rule violation when the docstring includes the exception.

ruff==0.5.5
python==3.12.4

Command: ruff check --preview --select DOC

No pyproject.toml or other configuration than what's shown here.

Steps to reproduce
Sample file to test against.

class Foo:
    def __init__(self, bar, zap):
        self.bar = bar
        self.zap = zap
        
    def get_bar(self) -> str:
        """Print and return bar.
        
        Raises:
            ValueError: bar is not bar.

        Returns:
            str: bar value.
        """    
        print(self.bar)
        if self.bar != "bar":
            raise ValueError(self.bar)
        return self.bar

Expected behavior
No violations.

Running pydoclint --style=google test.py gives the expected no violation result.

Debug logs

test.py:17:19: DOC501 Raised exception `ValueError` missing from docstring
   |
15 |         print(self.bar)
16 |         if self.bar != "bar":
17 |             raise ValueError(self.bar)
   |                   ^^^^^^^^^^^^^^^^^^^^ DOC501
18 |         return self.bar
   |

Notes
Adding an argument to Foo.get_bar and adding that to the docstring then makes the DOC501 violation go away. Example below:

    def get_bar(self, x: str) -> str:
        """Print and return bar.
        
        Args:
            x (str): A dummy value.
        
        Raises:
            ValueError: bar is not bar.

        Returns:
            str: bar value
        """    
        print(self.bar)
        if self.bar != "bar":
            raise ValueError(self.bar)
        return self.bar

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocstringRelated to docstring linting or formatting

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions