Skip to content

[serve] Declare __all__ in ray.serve.request_router - #65485

Merged
abrarsheikh merged 1 commit into
masterfrom
doc-1470-request-router-all
Aug 14, 2026
Merged

abrarsheikh merged 1 commit into
masterfrom
doc-1470-request-router-all

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

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 #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 #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.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.

`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]>
@dstrodtman
dstrodtman requested a review from a team as a code owner August 14, 2026 12:07

@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 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.

@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Aug 14, 2026
@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Aug 14, 2026
@abrarsheikh
abrarsheikh merged commit 67dad80 into master Aug 14, 2026
6 checks passed
@abrarsheikh
abrarsheikh deleted the doc-1470-request-router-all branch August 14, 2026 17:16
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants