Repository navigation
[ci] Extend the docstring-only guard to Cython and .pyi files - #67599
Conversation
The docstring-only scope guard rejected every non-.py file, so docstring edits to Cython bindings couldn't use the label. Compare .pyi stubs with the existing ast rule, and compare .pyx, .pxi, and .pxd files by their tokenize token streams with comments and docstrings removed. Keep `# cython:` and `# distutils:` comments and `cdef extern from` C blocks as code, since both change the compiled module. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request extends the 'docstring-only' CI guard to support Cython files (.pyx, .pxi, and .pxd) by implementing a token-based comparison using Python's tokenize module, as Cython cannot be parsed by ast. It correctly handles Cython-specific constructs like build comments and verbatim C blocks. The feedback points out a potential issue in _owns_docstring where non-function async blocks (like async with or async for) could be incorrectly matched, and suggests restricting the check to async def blocks.
| if words[0] in ("def", "class", "async"): | ||
| return True |
There was a problem hiding this comment.
The current check words[0] in ("def", "class", "async") will incorrectly return True for other block headers starting with async, such as async with or async for. Since these blocks cannot have docstrings, any string literal at the start of their body could be incorrectly stripped as a docstring, potentially bypassing code checks. We should restrict the async check to only match async def function definitions.
| if words[0] in ("def", "class", "async"): | |
| return True | |
| if words[0] in ("def", "class") or (words[0] == "async" and len(words) > 1 and words[1] == "def"): | |
| return True |
There was a problem hiding this comment.
Fixed in 15e0d30: only async def now counts as a docstring owner, so the first string in an async with or async for body is compared as code. test_cython_async_block_string_is_code covers both headers.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dbae4eb. Configure here.
`async with` and `async for` headers also start with `async`, but their bodies have no docstring, so the first string in them is code. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
…odule, and connector pipeline APIs (#67629) ## Why are these changes needed? Several public methods and classes in `ray.rllib.algorithms`, `ray.rllib.core`, and `ray.rllib.connectors` have no docstring, no parameter entry, or no `Returns:` section. Most of them render on the RLlib API reference. This PR documents their existing behavior and changes only docstrings. What changed: - **`Algorithm`:** A docstring and `Returns:` for `get_default_config`. `Args:` and `Returns:` for `get_default_policy_class`. A docstring, `Args:`, and `Returns:` for `restore_offline_eval_runners`, modeled on `restore_env_runners`. A docstring and `Args:` for `load_checkpoint`. - **`Learner` and `LearnerGroup`:** Docstrings for `Learner.node` and `Learner.device`, and for `LearnerGroup.is_remote` and `is_local`. `Returns:` for `LearnerGroup.get_stats`, naming both keys. - **`RLModule`, `RLModuleSpec`, `MultiRLModule`, and `MultiRLModuleSpec`:** `Returns:` sections for `build`, `as_multi_rl_module_spec`, `as_multi_rl_module`, `is_stateful`, `to_dict`, the three `get_*_action_dist_cls` methods, and `MultiRLModule.items` and `keys`. Also a docstring, `Args:`, and `Returns:` for `RLModuleSpec.from_module`. - **Connector pipelines:** Class docstrings for `EnvToModulePipeline`, `LearnerConnectorPipeline`, and `ModuleToEnvPipeline`. Two of these correct an existing summary, so they need a closer look: - `MultiRLModule.items()` said it iterates "over the module IDs", but it yields (ModuleID, RLModule) pairs. `values()` has the same mistake in its docstring and in its `ValuesView[ModuleID]` return annotation. Fixing an annotation is a code change, so both `values()` fixes are in #67631. - `RLModule.as_multi_rl_module()` now says the returned MultiRLModule holds a newly built module rather than this instance. That's because `MultiRLModule.setup()` calls `RLModuleSpec.build()`. Rows left out on purpose: - Methods whose new `Args:` sections would need parameter type hints first. Ray's pydoclint configuration fails an `Args:` section on an unannotated signature. These are `RLlibCallback.on_workers_recreated`, `AgentToModuleMapping`, `Learner.apply`, both `from_dict` methods, and the two connector `__call__` methods with untyped `**kwargs`. They go in a separate PR without the label. - The `ConnectorV2.input_observation_space` and `input_action_space` setters. Sphinx renders a property from its getter's docstring only. ## Related issue number None. The work comes from the docs team's inventory of `@PublicAPI` symbols with missing docstrings. It follows #67626, which covers `ray.rllib.env`. I searched open PRs for RLlib docstring work and for these files and found no overlap. ## Checks - `pre-commit run --files <changed files>`: all hooks pass, including ruff, black, and pydoclint 0.9.1 with the repo's arguments. - `python ci/ray_ci/doc/check_docstring_only.py --base <merge-base>`, with both the guard from this PR's base and the guard as of #67599: `docstring-only guard: 8 file(s), docstrings only.` - No `>>>` examples were added or changed. The commit carries an `@rtd-build` line so Read the Docs builds a preview. AI assistance (Claude Code) was used to draft these docstrings. I reviewed every changed line against the code. 🤖 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]>
…atch, and utils APIs (#67630) ## Why are these changes needed? Several public methods and classes in `ray.rllib.offline`, `ray.rllib.policy.sample_batch`, and `ray.rllib.utils` have no docstring, no parameter entry, or no `Returns:` section. This PR documents their existing behavior and changes only docstrings. What changed: - **Offline:** - A class docstring with `Args:` for `OfflineData`, plus docstrings for `OfflineData.sample` and its two `default_*_batches_kwargs` properties. - `Args:` and `Returns:` for `OfflineSingleAgentEnvRunner.sample`, including when it writes its buffer. - `Args:` on the `OfflinePreLearner` class docstring. - A docstring for `get_offline_io_resource_bundles`. - Docstrings for `IOContext.input_config` and `output_config`. - **`SampleBatch` and `MultiAgentBatch`:** - `Returns:` for `agent_steps` and `env_steps`. - A docstring for `is_training` and `Args:` for `set_training`. - `Args:` and `Returns:` for `MultiAgentBatch.timeslices`. - **Utils:** - `Returns:` for `MetricsLogger.get_state`. - `Args:` and `Returns:` for `huber_loss` and for the torch and TensorFlow versions of `symlog` and `inverse_symlog`. - Docstrings for `sample()` on `FlexDict`, `Repeated`, and `Simplex`. `OfflineData.sample` and `OfflineSingleAgentEnvRunner.sample` have the most new content and need the closest read. `Repeated.sample()` is documented as returning 1 to `max_len` items, which is what it does. The `Repeated` class docstring's example still says "from 0 to 10 boxes", because `contains()` does accept an empty list. Rows left out on purpose: - Methods whose new `Args:` sections would need parameter type hints first. Ray's pydoclint configuration fails an `Args:` section on an unannotated signature. These are `MetricsLogger.log_dict`, `one_hot_multidiscrete`, `FlexDict.assertSpace`, `Repeated.contains`, `Simplex` and its `contains`, `to_jsonable`, and `from_jsonable`, and `SampleBatch.get`. They go in a separate PR without the label. - `SampleBatch.concat_samples` and `MultiAgentBatch.concat_samples`, which are `@Deprecated(error=True)` stubs. ## Related issue number None. The work comes from the docs team's inventory of `@PublicAPI` symbols with missing docstrings. It follows #67626, and its companion for `algorithms`, `core`, and `connectors` is #67629. I searched open PRs for RLlib docstring work and for these files and found no overlap. ## Checks - `pre-commit run --files <changed files>`: all hooks pass, including ruff, black, and pydoclint 0.9.1 with the repo's arguments. - `python ci/ray_ci/doc/check_docstring_only.py --base <merge-base>`, with both the guard from this PR's base and the guard as of #67599: `docstring-only guard: 13 file(s), docstrings only.` - No `>>>` examples were added or changed. The commit carries an `@rtd-build` line so Read the Docs builds a preview. AI assistance (Claude Code) was used to draft these docstrings. I reviewed every changed line against the code. 🤖 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]>

Why are these changes needed?
The
docstring-onlylabel's scope guard,ci/ray_ci/doc/check_docstring_only.py, rejects every file that isn't.py. Docstring edits to Cython bindings therefore can't use the label, even when they change nothing else. #67592 hit this: its edits topython/ray/includes/gcs_client.pxiandglobal_state_accessor.pxionly add and rewrite docstrings, and the guard failed them with "isn't a Python file" (build 75788).This PR extends the guard to two more kinds of file:
.pyistubs are Python, so they go through the existingastcomparison unchanged..pyx,.pxi, and.pxd, can't go throughast, which can't parsecdef. The guard compares theirtokenizetoken streams instead. It drops comments, blank lines, and line breaks inside brackets. It removes a string only where Python allows a docstring: the first statement of the file, or the first statement in the indented body of adef,class,cdef/cpdeffunction, orcdef class.Two Cython constructs look like comments or docstrings but are code, and the guard keeps both:
# cython:and# distutils:comments set compiler directives and build options._raylet.pyx,_raylet.pxd, andlibcoreworker.pxdcarry them, includingembedsignature.cdef extern fromblock is verbatim C or C++ that Cython compiles. Five files underpython/ray/have one. Acdef externheader has neither a parameter list norclass, so the guard never treats that string as a docstring.The token comparison fails closed where it differs from the
astrule. It treats replacing a docstring-only body withpassas a code change, and it doesn't strip a docstring written on the same line as itsdef.The label still compiles the PR's Cython. A
python/change selectsdoc: docstring examples, which depends onray-core-build, so a docstring edit that breaks the Cython build still fails the PR.ci.md,ci/ray_ci/doc/README.md, and the step comment in.buildkite/lint.rayci.ymlnow name the covered file types and the two Cython exceptions.ci.mdalso notes thatdoc: docstring examplesruns only Python modules. No CI step runs>>>examples in Cython docstrings, with or without the label, because nodoctest()target lists a Cython file and--doctest-modulescollects only.py.Testing
pytest ci/ray_ci/doc/test_check_docstring_only.pypasses all 33 tests on Python 3.10, which is the forge image's version, and on 3.12 and 3.13. The new tests cover stub docstrings, the [Docs][Core] Specify if the node id needs to be a hex or byte value #67592 edit shapes, line rewrapping, indentation changes, the build comments, the extern C block, a non-leading string, an f-string in the docstring position, a Cython cast, anexcept?clause, and a tokenize error..pyx,.pxi,.pxd, and.pyifiles on master tokenize on Python 3.10 through 3.13.pre-commit runon the changed files passes.Duplicate check
No open PR changes
check_docstring_only.pyor the label's file coverage. I searched open PRs for "docstring-only" and "check_docstring_only".AI assistance
I wrote this change with Claude Code (Opus 5.5). I reviewed every changed line, and I ran the tests and checks listed above.
🤖 Generated with Claude Code