You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8ebb34e
Browse filesBrowse the repository at this point in the historyBrowse files
[pydocstyle] Treat backslash-escaped *args and **kwargs as documented (D417) (#29536)
## Summary
Closes#29535.
Sphinx-style docstrings often escape the stars as `\*args` and
`\*\*kwargs`, because a bare `*` starts emphasis in reST. D417 didn't
account for that, so it reported those parameters as undocumented even
though they were documented.
It went wrong in a different way for each style. In NumPy-style
sections, the name before the `:` was taken verbatim, so `\*\*kwargs`
never matched `**kwargs`. In Google-style sections, the regex didn't
accept a leading `\`, so the whole line was skipped.
I added a small `unescape_parameter_name` helper in `sections.rs` that
strips backslashes from the documented name, and both parsers now use
it. The Google regex also accepts up to two escaped stars now. Since a
backslash can't be part of a Python parameter name, removing all of them
should be safe. This also covers non-raw docstrings that write
`\\*\\*kwargs`.
## Test Plan
I added five cases to `D417.py`: escaped NumPy and Google docstrings
with every parameter documented, the same two styles with one parameter
actually missing, and a non-raw docstring. Without the fix, all five
`d417` tests fail and report `*args` and `**kwargs` as missing. With the
fix, the fully documented functions aren't flagged. In the missing
variants, only the parameters that really are missing get reported. The
snapshots are updated, and `cargo test -p ruff_linter -- pydocstyle` and
clippy both pass.
I used Claude (via T3 Code) to help with the implementation. I've
reviewed the change and can explain it.
Copy file name to clipboardExpand all lines: crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__d417_google_ignore_var_parameters.snap
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -93,3 +93,11 @@ D417 Missing argument description in the docstring for `function_with_unpack_and
Copy file name to clipboardExpand all lines: crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__d417_unspecified.snap
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -111,3 +111,19 @@ D417 Missing argument description in the docstring for `function_with_unpack_and
Copy file name to clipboardExpand all lines: crates/ruff_linter/src/rules/pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__d417_unspecified_ignore_var_parameters.snap
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -111,3 +111,19 @@ D417 Missing argument description in the docstring for `function_with_unpack_and
0 commit comments