Repository navigation
[pydocstyle] Treat backslash-escaped *args and **kwargs as documented (D417) - #29536
Merged
Merged
Conversation
… `D417` (astral-sh#29535) reStructuredText requires `*` to be escaped as `\*`, so Sphinx-oriented docstrings document variadic parameters as `\*args` and `\*\*kwargs`. Strip the escaping backslashes from the documented names (NumPy and Google styles) before comparing them against the signature, and let the Google argument regex match a leading backslash.
|
This comment was marked as spam.
This comment was marked as spam.
ntBre
approved these changes
Oct 20, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thank you!
Replacing all backslashes means we'll be a little overly permissive. For example, we'd convert something invalid like foo\\bar to foobar, rather than only replacing \*, but I think that's okay.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #29535.
Sphinx-style docstrings often escape the stars as
\*argsand\*\*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\*\*kwargsnever 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_namehelper insections.rsthat 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 fived417tests fail and report*argsand**kwargsas 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, andcargo test -p ruff_linter -- pydocstyleand clippy both pass.I used Claude (via T3 Code) to help with the implementation. I've reviewed the change and can explain it.