Skip to content

[core] Hand-fix the ten D212 docstrings the auto-fix would mis-render - #67601

Merged
dstrodtman merged 3 commits into
masterfrom
doc-1916-d212-docstring-fixes
Nov 4, 2026
Merged

dstrodtman merged 3 commits into
masterfrom
doc-1916-d212-docstring-fixes

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

This follows #67540, which merged on 2026-11-02 and applied ruff's D212 and D200 auto-fixes to python/ray/ outside the library trees. That PR left ten D212 violations in place because the auto-fix would change what they render as. Each has a first line indented less than the lines below 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. 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 material below it re-indented as a block or section. Every summary comes from the existing text or from the code:

  • metrics_reporter.py report_instances and report_resources, scheduler.py _sort_gang_resource_requests, job_log_storage_client.py get_log_file_path, and the util/dask/scheduler_utils.py module docstring get a summary line. The existing content stays below it.
  • dag/dag_node.py DAGNode.__init__ gets a summary and a capitalized Args: section. The entries drop the types already in the signature, and the ex: lines become "For example, ...".

Three docstrings changed beyond layout, because the existing text didn't match the code. These need a close read:

  • instance_manager/config.py get_docker_config: the old text listed a "node specific docker image" as the first choice for head nodes. In ray-schema.json, a node type's docker block allows only worker_image, pull_before_run, and worker_run_options, so the head-node order is head_image, then image. The worker-node order now names the node type's docker.worker_image explicitly.
  • instance_manager/config.py FileConfigReader and KubeRayConfigReader get_cached_autoscaling_config: these overrides had only a Returns: block and no summary. They now have no docstring and inherit the abstract IConfigReader.get_cached_autoscaling_config docstring.
  • aws/utils.py LazyDefaultDict.__missing__: the pseudo-code was copied from collections.defaultdict and described a factory that takes no argument and a KeyError for a None factory. This override calls default_factory(key), so the docstring now says that.

One thing outside this PR's scope: JobLogStorageClient.get_log_file_path is annotated -> Tuple[str, str], but it returns a single str. Fixing the annotation is a code change, so it's in #67602 instead.

Testing

  • uvx [email protected] check --select D212 --config 'lint.pydocstyle.convention="google"' on the seven changed files: all checks passed.
  • python ci/ray_ci/doc/check_docstring_only.py --base doc-1903-core-docstring-autofix: docstring-only guard: 7 file(s), docstrings only.
  • The full pre-commit suite on the changed files, including ruff, black, pydoclint, and the docstyle hook: passed.

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

🤖 Generated with Claude Code

dstrodtman and others added 2 commits October 29, 2026 09:48
Run ruff 0.8.4 `check --fix --unsafe-fixes --select D212,D200,D210`
under the Google pydocstyle convention over python/ray/, excluding the
library trees with their own code owners (data, serve, train, air, tune,
rllib, llm), test code, and generated code. The diff is formatter output
only.

Ten 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]>
Give each docstring a summary on the opening quotes and re-indent the
material below it as a block or section, so the D212 rule can be turned
on without changing what these docstrings render as.

Where the existing text disagreed with the code, the text now follows
the code: get_docker_config's head-node image order, and
LazyDefaultDict.__missing__, whose copied defaultdict pseudo-code
described a different factory signature. The two
get_cached_autoscaling_config overrides drop their summary-less
docstrings and inherit IConfigReader's.

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added core Issues that should be addressed in Ray Core docstring-only Skip heavy library tests for Ray API docstring edits. labels Oct 30, 2026
@dstrodtman
dstrodtman requested a review from a team as a code owner October 30, 2026 13:46

@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 focuses on cleaning up, formatting, and improving docstrings across various modules, including the autoscaler, DAG node, dashboard, and scheduler utilities. A review comment suggests a minor phrasing improvement in the DAG node initialization docstring to clarify that ClassMethodNode is a subclass implementation rather than a bound keyword argument.

Comment on lines +58 to +60
other_args_to_resolve: Bound kwargs to resolve that are specific
to a subclass implementation, without exposing them as args
in the base class. For example, ``ClassMethodNode``.

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.

medium

The phrasing "For example, ClassMethodNode" is slightly ambiguous because ClassMethodNode is a subclass implementation rather than a bound keyword argument. Clarifying this to "For example, in ClassMethodNode" or "such as in ClassMethodNode" improves readability.

Suggested change
other_args_to_resolve: Bound kwargs to resolve that are specific
to a subclass implementation, without exposing them as args
in the base class. For example, ``ClassMethodNode``.
other_args_to_resolve: Bound kwargs to resolve that are specific
to a subclass implementation, without exposing them as args
in the base class. For example, in 'ClassMethodNode'.

pseudo-rnd-thoughts added a commit that referenced this pull request Nov 2, 2026
## Why are these changes needed?

The ruff pre-commit hook is pinned to v0.8.4 (Dec 2024). This bumps it
to v0.17.3 without changing what gets linted, so we can later opt into
newer rules (e.g. `ASYNC`, `RUF100`) one group at a time.

- `.pre-commit-config.yaml`: `rev: v0.8.4` → `rev: v0.17.3`.
- `pyproject.toml`: newer ruff enables a much larger default rule set
(413 enabled rules under our config vs 109 on 0.8.4, ~40k findings).
Because our config only uses `extend-select`, I pinned `select = ["E4",
"E7", "E9", "F"]` (the old defaults) to keep behaviour unchanged.
- `pyproject.toml`: ignored `C420` (unnecessary dict comprehension), a
C4 rule added after 0.8.4. It flags 71 existing sites across rllib,
serve, data, tune, train, dag and the dashboard. All are auto-fixable,
so it can be enabled with `--fix` in a follow-up rather than pinging
every CODEOWNER here.

No Python source changes.

## Duplicate check

`gh pr list --state open --search "ruff"` turns up #67540 and #67601,
which apply ruff docstring fixes to source files. Neither changes the
ruff version, `.pre-commit-config.yaml` or `pyproject.toml`, so this
doesn't overlap with them.

## Testing

Run over all tracked `.py`/`.pyi` files except `doc/` and
`python/ray/cloudpickle/` (both already have violations on 0.8.4), with
`--force-exclude` as the hook uses:

- `[email protected] check --force-exclude` (main hook): passes, 0 findings
(0.8.4 on master: also 0).
- `[email protected] check --force-exclude --select I` (import-sort hook): 1
finding in `python/ray/_private/runtime_env/_clonevirtualenv.py`, the
same as on 0.8.4, so it already exists.
- `pre-commit run check-toml --files pyproject.toml`: passes.

Ruff 0.17.3 also prints a non-fatal warning about two existing `# noqa:
type` comments in
`python/ray/data/_internal/planner/plan_all_to_all_op.py`. I left them
unchanged here.

I haven't run `pre-commit run --all-files`.

## AI assistance

AI assistance (Claude Code) was used to measure the findings and make
this change. I reviewed the diff.

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

Signed-off-by: Mark Towers <[email protected]>
Co-authored-by: Mark Towers <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@dstrodtman
dstrodtman force-pushed the doc-1903-core-docstring-autofix branch from 1b51db7 to 06da8f9 Compare November 2, 2026 20:06
Base automatically changed from doc-1903-core-docstring-autofix to master November 2, 2026 23:59
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Nov 3, 2026
@dstrodtman
dstrodtman merged commit fecb643 into master Nov 4, 2026
7 checks passed
@dstrodtman
dstrodtman deleted the doc-1916-d212-docstring-fixes branch November 4, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docstring-only Skip heavy library tests for Ray API docstring edits. go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants