Skip to content

[ci/doc] Exempt override hooks from the API-doc private-name rule - #64818

Merged
elliot-barn merged 2 commits into
ray-project:masterfrom
dstrodtman:doc-1400-exempt-override-hooks
Jul 17, 2026
Merged

elliot-barn merged 2 commits into
ray-project:masterfrom
dstrodtman:doc-1400-exempt-override-hooks

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Why

The API-doc consistency check (ci/ray_ci/doc/api.py, cmd_check_api_discrepancy.py) flags any documented API whose canonical name is private, where _is_private_name() treats a leading-underscore final segment as private. That heuristic conflates the two meanings a single leading underscore carries in Python. PEP 8 uses it for "non-public / no stability guarantee," which is what the check wants to catch. But with no protected keyword, the same underscore also marks a template-method override hook: a public, non-overridable wrapper that delegates to a protected, user-overridable method. That hook is an intentional, documented extension point, not a private leak.

RLlib relies on this pattern. RLModule._forward, _forward_exploration, _forward_inference, and _forward_train are documented in doc/source/rllib/package_ref/rl_modules.rst ("Override these private methods to define your custom model's forward behavior"). Users call the public forward_train and override _forward_train. The check flags all four as non-public purely because of the leading underscore, even though they resolve cleanly and are the documented contract for subclassing a @PublicAPI(stability="beta") class. They were parked in the RLlib tracked_doc_debt list to green the check, which records the exception by name and grows with every new documented override hook.

What

Teach the check to exempt an underscore-named object from the private-name rule when it carries the __is_overridden__ marker that @OverrideToImplementCustomLogic (and the _CallToSuperRecommended variant) sets. A method tagged as an intentional override hook is a declared public extension point, so its leading underscore should not read as "private." This keys the exemption off an explicit, machine-readable signal of intent instead of a hand-maintained name list.

  • ci/ray_ci/doc/api.py — add API._is_override_hook(obj) and apply it in split_resolvable_and_broken_doc_apis. The exemption reads the attribute generically (hasattr(obj, "__is_overridden__")), so the shared check needs no RLlib import. It affects only the non-public classification; the unresolved-name and duplicate-documentation checks are unchanged. A @Deprecated annotation is still fatal, and a plain _helper with no marker still fails.
  • ci/ray_ci/doc/cmd_check_api_discrepancy.py — retire the four RLModule._forward* entries from the RLlib tracked-doc-debt list, now covered by the marker exemption. The genuine private/dunder entries stay.
  • ci/ray_ci/doc/mock/mock_module.py, test_api.py — add coverage for a documented underscore method that is / isn't tagged as an override hook.

Note on the signal: the decorators set __is_overridden__ = False on the base method, and is_overridden() returns True by default for undecorated objects, so the intent signal is the presence of the attribute, not its value.

Checks

  • ci/ray_ci/doc/test_api.py and ci/ray_ci/doc/test_cmd_check_api_discrepancy.py pass locally.
  • Full pre-commit suite (ruff/black/import-order/docstyle/semgrep) passes.
  • The doc: check API doc consistency premerge job is the authoritative gate.

Related

Overlaps the RLlib config block edited by #64807 (short-term whitelist + .rst fixes) — this exemption makes the four _forward* debt entries dead, so once it lands the RLlib side is covered regardless of merge order. The classification function is also touched by the analogous Data __all__ signal-over-whitelist change; whichever merges second rebases.

The API-doc consistency check flags any documented API whose canonical
name is private (a leading-underscore final segment). That conflates PEP
8 "non-public" with Python's template-method override hook: a public,
non-overridable wrapper delegating to a protected, user-overridable
method (for example `RLModule.forward_train` delegating to the
documented, subclassable `_forward_train`). Those hooks are declared
public extension points, not private leaks.

Exempt an underscore-named object from the private-name rule when it
carries the `__is_overridden__` marker that the
`@OverrideToImplementCustomLogic` decorators set. Presence of the
attribute is the intent signal, and the check reads it generically so the
shared check needs no per-team import. Deprecated annotations are still
fatal, and a plain private member with no marker still fails.

Retire the `RLModule._forward*` override-hook entries from the RLlib
tracked-doc-debt list, now covered by the marker exemption, and add unit
coverage for a marked versus unmarked underscore method.

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested a review from a team as a code owner July 16, 2026 18:34

@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 introduces a mechanism to identify and exempt 'override hooks' from being flagged as private APIs in the documentation check. It adds a helper method _is_override_hook to API that checks for the __is_overridden__ attribute, updates the API resolution logic to respect this marker, and includes corresponding updates to the mock module and test suite. I have suggested centralizing the __is_overridden__ attribute name as a constant to improve maintainability across the codebase.

Comment thread ci/ray_ci/doc/api.py Resolved
Comment thread ci/ray_ci/doc/mock/mock_module.py Resolved
Define _OVERRIDE_HOOK_MARKER in api.py and reference it from both the
check and the test mock, instead of repeating the literal attribute name.

Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman force-pushed the doc-1400-exempt-override-hooks branch from 71c96de to 46e280e Compare July 16, 2026 18:48
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Jul 16, 2026
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation devprod labels Jul 16, 2026
@elliot-barn
elliot-barn merged commit 1828492 into ray-project:master Jul 17, 2026
6 checks passed
ArturNiederfahrenhorst added a commit to ArturNiederfahrenhorst/ray that referenced this pull request Jul 20, 2026
Resolve the cmd_check_api_discrepancy.py conflict with ray-project#64818: drop master's
rllib tracked_doc_debt block (superseded) and keep this PR's real fixes.
The four RLModule._forward* whitelist entries are removed — they are now
exempted generically by the @OverrideToImplementCustomLogic marker added in
 ray-project#64818 (API._is_override_hook). Verified: the rllib API-doc check passes
(exit 0) against the merged tree.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Artur Niederfahrenhorst <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…y-project#64818)

## Why

The API-doc consistency check (`ci/ray_ci/doc/api.py`,
`cmd_check_api_discrepancy.py`) flags any documented API whose canonical
name is private, where `_is_private_name()` treats a leading-underscore
final segment as private. That heuristic conflates the two meanings a
single leading underscore carries in Python. PEP 8 uses it for
"non-public / no stability guarantee," which is what the check wants to
catch. But with no `protected` keyword, the same underscore also marks a
**template-method override hook**: a public, non-overridable wrapper
that delegates to a protected, user-overridable method. That hook is an
intentional, documented extension point, not a private leak.

RLlib relies on this pattern. `RLModule._forward`,
`_forward_exploration`, `_forward_inference`, and `_forward_train` are
documented in `doc/source/rllib/package_ref/rl_modules.rst` ("Override
these private methods to define your custom model's forward behavior").
Users call the public `forward_train` and override `_forward_train`. The
check flags all four as non-public purely because of the leading
underscore, even though they resolve cleanly and are the documented
contract for subclassing a `@PublicAPI(stability="beta")` class. They
were parked in the RLlib `tracked_doc_debt` list to green the check,
which records the exception by name and grows with every new documented
override hook.

## What

Teach the check to exempt an underscore-named object from the
private-name rule when it carries the `__is_overridden__` marker that
`@OverrideToImplementCustomLogic` (and the `_CallToSuperRecommended`
variant) sets. A method tagged as an intentional override hook is a
declared public extension point, so its leading underscore should not
read as "private." This keys the exemption off an explicit,
machine-readable signal of intent instead of a hand-maintained name
list.

- **`ci/ray_ci/doc/api.py`** — add `API._is_override_hook(obj)` and
apply it in `split_resolvable_and_broken_doc_apis`. The exemption reads
the attribute generically (`hasattr(obj, "__is_overridden__")`), so the
shared check needs no RLlib import. It affects only the non-public
classification; the unresolved-name and duplicate-documentation checks
are unchanged. A `@Deprecated` annotation is still fatal, and a plain
`_helper` with no marker still fails.
- **`ci/ray_ci/doc/cmd_check_api_discrepancy.py`** — retire the four
`RLModule._forward*` entries from the RLlib tracked-doc-debt list, now
covered by the marker exemption. The genuine private/dunder entries
stay.
- **`ci/ray_ci/doc/mock/mock_module.py`, `test_api.py`** — add coverage
for a documented underscore method that is / isn't tagged as an override
hook.

Note on the signal: the decorators set `__is_overridden__ = False` on
the base method, and `is_overridden()` returns `True` by default for
undecorated objects, so the intent signal is the *presence* of the
attribute, not its value.

## Checks

- `ci/ray_ci/doc/test_api.py` and
`ci/ray_ci/doc/test_cmd_check_api_discrepancy.py` pass locally.
- Full pre-commit suite (ruff/black/import-order/docstyle/semgrep)
passes.
- The `doc: check API doc consistency` premerge job is the authoritative
gate.

## Related

Overlaps the RLlib config block edited by ray-project#64807 (short-term whitelist +
`.rst` fixes) — this exemption makes the four `_forward*` debt entries
dead, so once it lands the RLlib side is covered regardless of merge
order. The classification function is also touched by the analogous Data
`__all__` signal-over-whitelist change; whichever merges second rebases.

---------

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

Labels

devprod docs An issue or change related to documentation 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