Repository navigation
[serve] Declare __all__ in ray.serve.request_router - #65485
Merged
Merged
Conversation
`python/ray/serve/request_router.py` re-exports the public request-router extension surface, but declares it implicitly through `# noqa: F401` imports. Declare it explicitly instead. The seven names in `__all__` are each decorated `@PublicAPI(stability="alpha")` at their definition site and documented in the Serve API reference under their `serve.request_router.*` path, so this records an existing contract rather than creating a new one. It also lets the API-doc consistency check see the surface: `API._is_public_reexport()` requires an explicit `__all__` entry on a public module, which this module didn't have. `ReplicaResult` is left out. It carries no API annotation and has no reference page, so it isn't part of the documented surface. Its import keeps an F401 suppression since the re-export is still in use. Dropping the per-import suppressions on the seven declared names is safe: a name listed in `__all__` counts as used, so pyflakes/ruff no longer flag them. Signed-off-by: Douglas Strodtman <[email protected]>
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates python/ray/serve/request_router.py to explicitly define the public request-router extension surface using the __all__ list. It also cleans up unused # noqa: F401 comments for imports that are now explicitly exported. There are no review comments, and I have no feedback to provide.
abrarsheikh
approved these changes
Aug 14, 2026
400Ping
pushed a commit
to 400Ping/ray
that referenced
this pull request
Aug 18, 2026
## Why `python/ray/serve/request_router.py` re-exports the public request-router extension surface, but declares it implicitly through `# noqa: F401` imports rather than explicitly through `__all__`. This declares it. The seven names are each decorated `@PublicAPI(stability="alpha")` at their definition site and documented in the Serve API reference at `doc/source/serve/api/index.md` under their `serve.request_router.*` path. `doc/source/serve/advanced-guides/custom-request-router.md` and its `doc_code/custom_request_router.py` teach users to import from this module. So the change records an existing contract rather than creating a new one. It also makes the surface visible to the API-doc consistency check. `API._is_public_reexport()`, added in ray-project#65340, treats a name in a public module's `__all__` as public regardless of where its implementation lives, but it requires an *explicit* `__all__` entry, which this module didn't have. ## Coordination This is a small mechanical change, so per `AGENTS.md` it's worth saying it was coordinated rather than volunteered. It follows from a ruling Richard Liaw gave on Ray's API location policy: a private definition re-exported through a public module's `__all__` is compliant, and the test that matters is whether users have to import a private package. Declaring the surface here is the fix that ruling implies. Happy to close this if the Serve team would rather handle the module differently. ## `ReplicaResult` is deliberately excluded It's the one name in the file left out of `__all__`, because unlike the other seven it carries no API annotation (`class ReplicaResult(ABC)`, no decorator) and has no reference-page entry. Including it would newly assert a public contract instead of recording one. Its import keeps an F401 suppression since the re-export is still in use. **This is the one judgment call in the PR and it's yours to make.** If Serve considers `ReplicaResult` part of the public extension surface, say so and I'll add it. `PowerOfTwoChoicesRequestRouter` is out of scope: it's absent from both this module's re-exports and the autosummary, so it needs a separate decision. ## Removing the per-import suppressions The seven declared names lose their `# noqa: F401` comments. A name listed in `__all__` counts as used, so pyflakes and ruff no longer flag it. `ReplicaResult` keeps its suppression. ## Testing Verified statically: - `ruff check python/ray/serve/request_router.py` — passes. - `black --check` and `ruff format --check` — already formatted. - Full `pre-commit run` on the changed file — all applicable hooks pass (ruff, black, pydoclint, docstyle, import order, semgrep). - Confirmed the declared `__all__` is exactly the set of seven names in the `serve.request_router.*` autosummary block, with no extras and nothing missing. **Not verified locally: `api_policy_check`.** It needs a Ray build, and master's Python source doesn't import against a released binary, so I'm relying on CI for that check rather than claiming a local run. The expected effect is on the resolve check only. I'm specifically *not* claiming this clears the `tracked_doc_debt` entries for these symbols: those fail the must-be-documented check, which ray-project#65340 explicitly left untouched. If CI shows any of them can drop, I'll follow up separately rather than bundling it here. ## Duplicate check No open PR touches `python/ray/serve/request_router.py`. ray-project#65410 (`[serve] Enforce type checking on the scheduling/routing modules`) touches `_private/request_router/request_router.py` but not this module, so no conflict. ## AI assistance AI-assisted, per `AGENTS.md`: the analysis and the patch were drafted with Claude Code, and I reviewed every changed line. Signed-off-by: Douglas Strodtman <[email protected]> Signed-off-by: 400Ping <[email protected]>
nadongjun
pushed a commit
to nadongjun/ray
that referenced
this pull request
Oct 6, 2026
## Why `python/ray/serve/request_router.py` re-exports the public request-router extension surface, but declares it implicitly through `# noqa: F401` imports rather than explicitly through `__all__`. This declares it. The seven names are each decorated `@PublicAPI(stability="alpha")` at their definition site and documented in the Serve API reference at `doc/source/serve/api/index.md` under their `serve.request_router.*` path. `doc/source/serve/advanced-guides/custom-request-router.md` and its `doc_code/custom_request_router.py` teach users to import from this module. So the change records an existing contract rather than creating a new one. It also makes the surface visible to the API-doc consistency check. `API._is_public_reexport()`, added in ray-project#65340, treats a name in a public module's `__all__` as public regardless of where its implementation lives, but it requires an *explicit* `__all__` entry, which this module didn't have. ## Coordination This is a small mechanical change, so per `AGENTS.md` it's worth saying it was coordinated rather than volunteered. It follows from a ruling Richard Liaw gave on Ray's API location policy: a private definition re-exported through a public module's `__all__` is compliant, and the test that matters is whether users have to import a private package. Declaring the surface here is the fix that ruling implies. Happy to close this if the Serve team would rather handle the module differently. ## `ReplicaResult` is deliberately excluded It's the one name in the file left out of `__all__`, because unlike the other seven it carries no API annotation (`class ReplicaResult(ABC)`, no decorator) and has no reference-page entry. Including it would newly assert a public contract instead of recording one. Its import keeps an F401 suppression since the re-export is still in use. **This is the one judgment call in the PR and it's yours to make.** If Serve considers `ReplicaResult` part of the public extension surface, say so and I'll add it. `PowerOfTwoChoicesRequestRouter` is out of scope: it's absent from both this module's re-exports and the autosummary, so it needs a separate decision. ## Removing the per-import suppressions The seven declared names lose their `# noqa: F401` comments. A name listed in `__all__` counts as used, so pyflakes and ruff no longer flag it. `ReplicaResult` keeps its suppression. ## Testing Verified statically: - `ruff check python/ray/serve/request_router.py` — passes. - `black --check` and `ruff format --check` — already formatted. - Full `pre-commit run` on the changed file — all applicable hooks pass (ruff, black, pydoclint, docstyle, import order, semgrep). - Confirmed the declared `__all__` is exactly the set of seven names in the `serve.request_router.*` autosummary block, with no extras and nothing missing. **Not verified locally: `api_policy_check`.** It needs a Ray build, and master's Python source doesn't import against a released binary, so I'm relying on CI for that check rather than claiming a local run. The expected effect is on the resolve check only. I'm specifically *not* claiming this clears the `tracked_doc_debt` entries for these symbols: those fail the must-be-documented check, which ray-project#65340 explicitly left untouched. If CI shows any of them can drop, I'll follow up separately rather than bundling it here. ## Duplicate check No open PR touches `python/ray/serve/request_router.py`. ray-project#65410 (`[serve] Enforce type checking on the scheduling/routing modules`) touches `_private/request_router/request_router.py` but not this module, so no conflict. ## AI assistance AI-assisted, per `AGENTS.md`: the analysis and the patch were drafted with Claude Code, and I reviewed every changed line. Signed-off-by: Douglas Strodtman <[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
python/ray/serve/request_router.pyre-exports the public request-router extension surface, but declares it implicitly through# noqa: F401imports rather than explicitly through__all__. This declares it.The seven names are each decorated
@PublicAPI(stability="alpha")at their definition site and documented in the Serve API reference atdoc/source/serve/api/index.mdunder theirserve.request_router.*path.doc/source/serve/advanced-guides/custom-request-router.mdand itsdoc_code/custom_request_router.pyteach users to import from this module. So the change records an existing contract rather than creating a new one.It also makes the surface visible to the API-doc consistency check.
API._is_public_reexport(), added in #65340, treats a name in a public module's__all__as public regardless of where its implementation lives, but it requires an explicit__all__entry, which this module didn't have.Coordination
This is a small mechanical change, so per
AGENTS.mdit's worth saying it was coordinated rather than volunteered. It follows from a ruling Richard Liaw gave on Ray's API location policy: a private definition re-exported through a public module's__all__is compliant, and the test that matters is whether users have to import a private package. Declaring the surface here is the fix that ruling implies. Happy to close this if the Serve team would rather handle the module differently.ReplicaResultis deliberately excludedIt's the one name in the file left out of
__all__, because unlike the other seven it carries no API annotation (class ReplicaResult(ABC), no decorator) and has no reference-page entry. Including it would newly assert a public contract instead of recording one. Its import keeps an F401 suppression since the re-export is still in use.This is the one judgment call in the PR and it's yours to make. If Serve considers
ReplicaResultpart of the public extension surface, say so and I'll add it.PowerOfTwoChoicesRequestRouteris out of scope: it's absent from both this module's re-exports and the autosummary, so it needs a separate decision.Removing the per-import suppressions
The seven declared names lose their
# noqa: F401comments. A name listed in__all__counts as used, so pyflakes and ruff no longer flag it.ReplicaResultkeeps its suppression.Testing
Verified statically:
ruff check python/ray/serve/request_router.py— passes.black --checkandruff format --check— already formatted.pre-commit runon the changed file — all applicable hooks pass (ruff, black, pydoclint, docstyle, import order, semgrep).__all__is exactly the set of seven names in theserve.request_router.*autosummary block, with no extras and nothing missing.Not verified locally:
api_policy_check. It needs a Ray build, and master's Python source doesn't import against a released binary, so I'm relying on CI for that check rather than claiming a local run. The expected effect is on the resolve check only. I'm specifically not claiming this clears thetracked_doc_debtentries for these symbols: those fail the must-be-documented check, which #65340 explicitly left untouched. If CI shows any of them can drop, I'll follow up separately rather than bundling it here.Duplicate check
No open PR touches
python/ray/serve/request_router.py. #65410 ([serve] Enforce type checking on the scheduling/routing modules) touches_private/request_router/request_router.pybut not this module, so no conflict.AI assistance
AI-assisted, per
AGENTS.md: the analysis and the patch were drafted with Claude Code, and I reviewed every changed line.