Repository navigation
[ci/doc] Exempt override hooks from the API-doc private-name rule - #64818
Merged
elliot-barn merged 2 commits intoJul 17, 2026
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
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.
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
force-pushed
the
doc-1400-exempt-override-hooks
branch
from
July 16, 2026 18:48
71c96de to
46e280e
Compare
elliot-barn
approved these changes
Jul 17, 2026
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]>
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.
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 noprotectedkeyword, 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_trainare documented indoc/source/rllib/package_ref/rl_modules.rst("Override these private methods to define your custom model's forward behavior"). Users call the publicforward_trainand 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 RLlibtracked_doc_debtlist 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_CallToSuperRecommendedvariant) 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— addAPI._is_override_hook(obj)and apply it insplit_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@Deprecatedannotation is still fatal, and a plain_helperwith no marker still fails.ci/ray_ci/doc/cmd_check_api_discrepancy.py— retire the fourRLModule._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__ = Falseon the base method, andis_overridden()returnsTrueby default for undecorated objects, so the intent signal is the presence of the attribute, not its value.Checks
ci/ray_ci/doc/test_api.pyandci/ray_ci/doc/test_cmd_check_api_discrepancy.pypass locally.doc: check API doc consistencypremerge job is the authoritative gate.Related
Overlaps the RLlib config block edited by #64807 (short-term whitelist +
.rstfixes) — 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.