ruff: Variable named "args" leads to ambiguous docstring parsing
Hello! I usually use PyDocStyle to check my docstrings and recently found that that project was deprecated and archived, so they recommended using Ruff instead, so I installed it to test it.
Ruff version is ruff 0.1.11
This is my configuration file:
[project]
requires-python = ">=3.11"
[tool.ruff.lint]
extend-select = [
"UP", # pyupgrade
"D", # pydocstyle
]
[tool.ruff.lint.pydocstyle]
convention = "google"
But I quickly found that Ruff was giving me warnings for docstrings that didn’t had any problems, because it was confusing the “args” argument name with the “Args” section of the docstring, which generated up to 5 different warnings.
The following is a mock method that shows the problem:
"""Test module for Ruff."""
from typing import Any
def select_data(
query: str,
args: tuple[Any],
database: str,
auto_save: bool,
) -> None:
"""Take a list of arguments to query the database and return it.
Args:
query:
Query template.
args:
A list of arguments.
database:
Which database to connect to ("origin" or "destination").
auto_save:
True for saving the query response in a CSV file.
Returns:
Returns the database data obtained from the query.
Raises:
ValueError:
When the database value does not match a supported option.
"""
print(query, args, database, auto_save)
For this file, Ruff gives this output:
$ ruff test.py
test.py:5:5: D417 Missing argument descriptions in the docstring for `select_data`: `args`, `auto_save`, `database`
test.py:11:5: D410 [*] Missing blank line after section ("Args")
test.py:11:5: D405 [*] Section name should be properly capitalized ("args")
test.py:11:5: D214 [*] Section is over-indented ("args")
test.py:11:5: D411 [*] Missing blank line before section ("args")
Found 5 errors.
[*] 4 fixable with the `--fix` option.
It does not recognize the descriptions of any argument after “args” and applies the Section rules to the argument, causing all those warnings. The “args” argument is fairly common in my work, so this means that I cannot replace pydocstyle with ruff yet, which is a pity since ruff looks pretty powerful.
If I change the “args” argument name to something else or if I just change args:
to args :
, the messages go away, so it’s obvious that Ruff is looking for a case insensitive “whitespace-args:”… Unfortunately, I don’t know to code in Rust to try to find a fix, but a suggestion is that maybe you can put an internal flag on which once the “Args:” section is correctly found, it considers any other “args” as argument (especially those in lowercase) in the docstring.
Thanks in advance!
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 17 (14 by maintainers)
Fixed, will go out in the next release!