terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
481 stars 41 forks source link

False positive DAR101 and DAR102 with raw docstring and variadic arguments. #167

Closed MT-0 closed 3 years ago

MT-0 commented 3 years ago

With the test.py file:

def test_function(*args: int) -> int:
    r"""Test a docstring with variadic arguments.

    Args:
        \*args:
            A list of integers.

    Returns:
        int: The first number else 0.
    """
    return args[0] if args else 0

and the .darglint file:

[darglint]
docstring_style = google
strictness = full

Running darglint test.py outputs:

test.py:test_function:4: DAR101: - *args
test.py:test_function:5: DAR102: + \*args
terrencepreilly commented 3 years ago

It's because of the backslash. A backslash isn't necessary, because there's no pattern matching or anything; an '' is just an ''. You should be able to change "*args" to "*args" or "args" and it ought to work.

MT-0 commented 3 years ago

This arose from a conflict between the errors raise by darglint and flake8-rst-docstrings. The above code validates using flake8-rst-docstrings but does not in darglint and removing the backslash then the reverse is true.

Looking at https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html#example-google then it seems that the backslash is expected outside the "Args" section (so that * is not interpreted as the start of an emphasis block) but there is a special case in the "Args" section where it is not expected.

It looks like there is an open issue in flake8-rst-docstrings about this and it needs fixing at their end rather than in this package.