Skip to content

[rllib] Apply ruff D212, D200, and D210 docstring auto-fixes - #67538

Merged
pseudo-rnd-thoughts merged 1 commit into
masterfrom
doc-1908-rllib-docstring-autofix
Oct 29, 2026
Merged

pseudo-rnd-thoughts merged 1 commit into
masterfrom
doc-1908-rllib-docstring-autofix

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Ray's code style guide says a docstring's first sentence starts on the opening quotes, and nothing enforces it yet. This PR clears ruff's auto-fixable docstring format rules from python/ray/rllib/, including @OldAPIStack modules, because the follow-up config PR needs every file clean, so a later config PR can turn them on without a baseline. Ruff has no baseline mechanism, so every library has to be clean first. Each library gets its own PR so that one code-owner team can review it.

The diff is formatter output only. It moves summaries onto the opening quotes (D212), collapses one-line docstrings onto one line (D200), and strips a leading space inside one docstring's quotes (D210). Nothing else changes, and no docstring text is reworded.

To reproduce:

uvx [email protected] check --fix --unsafe-fixes --select D212,D200,D210 \
  --config 'lint.pydocstyle.convention="google"' \
  --extend-exclude '**/tests/**,**/test_*.py,**/*_test.py,**/conftest.py' \
  python/ray/rllib

Ruff marks every D200 fix as unsafe, so --unsafe-fixes is needed to apply them. The scope guard below confirms the result changes only docstrings, and a second check confirms it doesn't change what any docstring renders as.

This PR leaves four D212 violations in place, because the fix would change what those docstrings render as. Each one has a first line indented less than the lines that follow it, and inspect.cleandoc ignores the first line when it computes the common indent. So joining that line to the opening quotes dedents the rest of the docstring. The four are the size_bytes docstring in policy/sample_batch.py, which starts with Returns:, and the module docstrings of models/tf/layers/multi_head_attention.py, models/torch/modules/multi_head_attention.py, and examples/algorithms/bc/benchmark_rlunplugged_atari_pong_bc.py. They need a hand edit, which goes in a separate PR.

Duplicate check

No open PR applies ruff D fixes to this code. I searched open PRs for D212, pydocstyle, and docstring-only.

Testing

  • python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)": docstring-only guard: 90 file(s), docstrings only.
  • The full pre-commit suite on the changed files, including ruff, black, pydoclint, and the docstyle hook: passed.
  • A check that inspect.cleandoc(__doc__), the text Sphinx autodoc renders, is identical before and after for every docstring in the changed files: 90 files, 0 docstrings changed.
  • The same ruff command without --fix: the 4 D212 violations above remain.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with Claude Code

Run ruff 0.8.4 `check --fix --unsafe-fixes --select D212,D200,D210`
under the Google pydocstyle convention over python/ray/rllib/, excluding
test code. The diff is formatter output only.

Four docstrings keep their original layout, because moving their first
line onto the quotes would change their rendered text. They need a hand
edit in a separate PR.

@rtd-build

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added rllib RLlib related issues go add ONLY when ready to merge, run all tests docstring-only Skip heavy library tests for Ray API docstring edits. labels Oct 29, 2026
@dstrodtman
dstrodtman requested a review from a team as a code owner October 29, 2026 13:44

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request standardizes docstring formatting across numerous files in the RLlib codebase by moving the initial line of text to the same line as the opening triple quotes. There are no review comments, and I have no feedback to provide.

@pseudo-rnd-thoughts
pseudo-rnd-thoughts merged commit 1235aff into master Oct 29, 2026
6 checks passed
@pseudo-rnd-thoughts
pseudo-rnd-thoughts deleted the doc-1908-rllib-docstring-autofix branch October 29, 2026 15:15
pseudo-rnd-thoughts pushed a commit that referenced this pull request Nov 3, 2026
…er (#67625)

## Why are these changes needed?

#67538 applied ruff's `D212`, `D200`, and `D210` auto-fixes to
`python/ray/rllib/`. It left four `D212` violations in place because the
auto-fix would change what they render as. This PR fixes them by hand so
a later config PR can turn on `D212`.

Each docstring now has a summary on the opening quotes, with the
existing material kept below it unchanged:

- `policy/sample_batch.py` `MultiAgentBatch.size_bytes` had only a
`Returns:` block. It now opens with a summary line that mirrors
`SampleBatch.size_bytes`.
- `models/tf/layers/multi_head_attention.py` and
`models/torch/modules/multi_head_attention.py` module docstrings get a
summary above the existing hanging-indent citation.
- `examples/algorithms/bc/benchmark_rlunplugged_atari_pong_bc.py` module
docstring gets a summary and a lead-in above the existing `schema={`
block, which keeps its original indentation.

For each docstring, the text `ast.get_docstring` returns before this
change is an exact suffix of the text it returns after, so the only
rendered change is the added summary.

## Testing

- `uvx [email protected] check --select D212 --config
'lint.pydocstyle.convention="google"'` on the four changed files: all
checks passed.
- `python ci/ray_ci/doc/check_docstring_only.py --base upstream/master`:
`docstring-only guard: 4 file(s), docstrings only.`
- `pre-commit run --from-ref upstream/master --to-ref HEAD`, including
ruff, black, pydoclint, and the docstyle hook: passed.

No open PR covers these docstrings. `gh pr list --search "D212 rllib"`
returns only the core-tree PR #67540.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docstring-only Skip heavy library tests for Ray API docstring edits. go add ONLY when ready to merge, run all tests rllib RLlib related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants