jsh9 / pydoclint

A Python docstring linter that checks arguments, returns, yields, and raises sections
https://pypi.org/project/pydoclint/
MIT License
151 stars 15 forks source link

Sphinx prefers escaping the asterisk for *args and **kwargs with a backslash but this confuses pydoclint #92

Closed tmke8 closed 1 year ago

tmke8 commented 1 year ago

Given this

def f(*args, **kwargs):
    """My function.

    :param *args: Positional args.
    :param **kwargs: Keyword args.
    """

sphinx throws a warning:

WARNING: Inline emphasis start-string without end-string.

and this also seems to mess with the formatting a bit.

But when it's escaped with a backslash, it's fine:

def f(*args, **kwargs):
    """My function.

    :param \\*args: Positional args.
    :param \\**kwargs: Keyword args.
    """

However, pydoclint then complains:

 DOC103: Function `f`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**kwargs: Any]. Arguments in the docstring but not in the function signature: [\**kwargs: ].

So, it seems the backslash confuses pydoclint.

jsh9 commented 1 year ago

Hi, I could not reproduce this issue. Could you double check your code snippet, and can you provide the configs that you used?

Thanks!

tmke8 commented 1 year ago

Oh, sorry about that! I didn't check that my minimal reproduction still had the error... rookie mistake.

It seems there need to be type annotations for this to happen:

from typing import Any

def f(*args: Any, **kwargs: Any) -> None:
    """My function.

    :param \\*args: Positional args.
    :param \\**kwargs: Keyword args.
    """

Save this as args_kwargs.py and run

pydoclint --style=sphinx --arg-type-hints-in-docstring=False --check-return-types=False --check-yield-types=False args_kwargs.py

gives

Loading config from user-specified .toml file: pyproject.toml
File "pyproject.toml" does not exist; nothing to load.
Skipping files that match this pattern: \.git|\.tox
args_kwargs.py
args_kwargs.py
    4: DOC103: Function `f`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [**kwargs: Any, *args: Any]. Arguments in the docstring but not in the function signature: [\**kwargs: , \*args: ].
jsh9 commented 1 year ago

Thanks for updating the example! I was able to reproduce it, and I made a code change to fix this bug.

jsh9 commented 1 year ago

Published as 0.3.8 on PyPI.

tmke8 commented 1 year ago

Thank you so much! You made a great tool!