Skip to content

[core] Add missing docstrings, and type hints where documenting needs them, to Ray Core public APIs - #67635

Merged
edoakes merged 3 commits into
masterfrom
doc-1919-core-util-docstrings
Nov 3, 2026
Merged

edoakes merged 3 commits into
masterfrom
doc-1919-core-util-docstrings

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Documents the public Ray Core symbols that are still missing docstrings, Args: entries, or Returns: sections in ray.util, ray.util.queue, ray.util.spark, ray.util.tpu, ray.experimental, ray.actor, ray.remote_function, ray.types, ray.exceptions, ray.runtime_env, ray.runtime_context, and ObjectRefGenerator. Each docstring describes existing behavior, written from the code.

Some of these symbols couldn't be documented without a signature change. Ray's pydoclint config rejects an Args: section until every parameter has a type hint, so this PR also adds type hints to the untyped public signatures it documents. It also corrects five return annotations that didn't match what the functions return.

#67540 applied the ruff D212 and D200 auto-fixes to these files, and #67634 documented ray.runtime_env, ray.exceptions, and ObjectRefGenerator. Both are merged. This PR builds on them and has two commits: the docstring additions, then the type annotations. The second commit was reviewed as #67636, which merged into this branch instead of master.

Because the signatures change, this PR isn't docstring-only and runs the full Core premerge.

Docstrings

  • ray.util.queue: Empty and Full are documented, and Queue.size, qsize, empty, and full have Returns: sections.
  • ray.util.list_named_actors documents all_namespaces and returns, including the dict entries it returns when all_namespaces is True.
  • ray.util.spark.setup_global_ray_cluster documents all 17 parameters and what it returns. Most entries follow the matching setup_ray_cluster parameter, which the existing docstring already says they share, and point to it for defaults and caps.
  • ray.util.tpu.dispatch, the deprecated alias of run_on_slice, gets Args: and Returns: sections. Adding Returns: makes pydoclint check *args and **kwargs, so they're documented too.
  • ray.experimental: CompiledDAGRef.get and the CompiledDAGFuture constructor parameters, the RayActorHandleResolver constructor and its get, forget, list_names, and kill methods, and the ReduceOp, AllGatherOp, AllReduceOp, ReduceScatterOp, and Device types are documented.
  • ActorMethod.__call__ and remote, ActorClassInheritanceException, RemoteFunction.__call__, and ray.types.ObjectRef have docstrings.

Type hints

Type hints added, with the parameters documented in the same change:

  • ObjectRefGenerator.send, throw, asend, and athrow: value: Any. Each method only raises NotImplementedError, and the docstrings say so.
  • RayError.from_bytes(b: bytes) -> BaseException and from_ray_exception(ray_exception: RayException) -> BaseException.
  • The constructors of CrossLanguageError, RayTaskError, RaySystemError, OutOfMemoryError, and NodeDiedError.
  • RuntimeContext.__init__(worker: Any). The worker is either the global Ray worker or Ray Client's _ClientWorkerPropertyAPI, which emulates it, so Any is the honest hint without new imports.
  • RuntimeEnv.get(name: str, default: Any = None, data_class: Optional[type] = None) -> Any and get_extension(key: str).

Return annotations corrected to match the code:

  • RuntimeEnv.has_conda: str to bool.
  • RuntimeEnv.conda_env_name and conda_config: str to Optional[str]. Both return None when conda isn't set or has the other form.
  • RuntimeEnv.py_container_run_options: List to Optional[List]. It returns None when container isn't set.
  • ray.util.list_named_actors: List[str] to Union[List[str], List[Dict[str, str]]]. With all_namespaces=True, it returns dicts with name and namespace keys.

AsyncioRouter in python/ray/serve/_private/router.py reads RayTaskError.cause into a local variable before the ActorDiedError check instead of calling getattr in the condition. It returns the same value in the same cases.

Type hints don't change runtime behavior. None of these files are in Ray's mypy hook.

For reviewers

CODEOWNERS adds two reviewers beyond @ray-project/ray-core: @ray-project/ray-serve for serve/_private/router.py, and one of the individual owners of util/tpu.py.

These are worth a close read:

  • setup_global_ray_cluster returns the (address, remote_connection_address) tuple only when is_blocking is False. When blocking, it returns None after the cluster shuts down.
  • CompiledDAGRef.get describes the timeout values from CompiledDAG._execute_until, which it calls. ray.get() on a CompiledDAGRef calls this method.
  • Device describes its members from the device argument of TorchTensorType.
  • RayTaskError.cause is hinted BaseException, which matches what the task-execution path in _raylet.pyx and CompiledDAG pass. actor_id is the actor ID in hex, as _raylet.pyx computes it.
  • RaySystemError.client_exc is hinted str. The callers in worker.py, serialization.py, and _raylet.pyx pass a message string, despite the parameter name.
  • RayError.from_bytes and from_ray_exception return BaseException: an unpickled exception, an UnserializableException, or a CrossLanguageError.

ray.util.client.api.ClientAPI.list_named_actors has the same List[str] annotation for Ray Client. It isn't public API, so this PR leaves it alone.

Duplicate check

No open PR documents these symbols or changes these signatures. I searched open PRs for the module, class, and method names. #66745 converts the Queue class docstring example to doctest form, which doesn't overlap the lines this PR changes.

Testing

These checks ran on each commit before the rebase onto master. The rebase applied both commits unchanged.

  • The full pre-commit suite on every changed file, including ruff, black, pydoclint, and the docstyle hook: passed.
  • uvx [email protected] check --select D212,D200,D210 on the changed files: passed.
  • The docstring commit passed ci/ray_ci/doc/check_docstring_only.py. The type-annotation commit changes signatures, so it's outside that guard by design.
  • A smoke test against the latest nightly wheel with the type-annotated files overlaid: a task error and an actor task error round-trip through to_bytes and from_bytes, ray.get_runtime_context() works in the driver and in an actor, the exception constructors format their messages, RuntimeEnv.get, get_extension, and the re-annotated accessors return what their annotations now say, and the streaming generator's send, throw, asend, and athrow raise NotImplementedError.
  • python/ray/tests/unit/test_runtime_env.py and test_runtime_env_validation.py against the same overlay: 96 passed, 12 failed. The same 12 fail with master's versions of those files in the same environment, because the nightly wheel's commit and the copied test fixtures don't match this checkout, so none come from this change.
  • Both commits carry an @rtd-build line, so the Read the Docs preview renders the changed docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with Claude Code

@dstrodtman dstrodtman added core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests docstring-only Skip heavy library tests for Ray API docstring edits. labels Oct 30, 2026
@dstrodtman
dstrodtman requested a review from a team as a code owner October 30, 2026 18:42
@dstrodtman dstrodtman added the docstring-only Skip heavy library tests for Ray API docstring edits. label Oct 30, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dstrodtman
dstrodtman force-pushed the doc-1919-core-util-docstrings branch from ed48c88 to da2c350 Compare October 30, 2026 18:55
@dstrodtman
dstrodtman changed the base branch from doc-1903-core-docstring-autofix to doc-1919-core-runtime-env-docstrings October 30, 2026 18:55
@dstrodtman
dstrodtman force-pushed the doc-1919-core-runtime-env-docstrings branch from 2e2960b to 2044e26 Compare November 2, 2026 20:06
@dstrodtman
dstrodtman force-pushed the doc-1919-core-util-docstrings branch from da2c350 to 27b0432 Compare November 2, 2026 20:06
dstrodtman added a commit that referenced this pull request Nov 3, 2026
…tions, and ObjectRefGenerator (#67634)

## Summary

Adds the missing docstrings, `Args:` entries, and `Returns:` sections on
public Ray Core symbols in `ray.runtime_env.runtime_env`,
`ray.exceptions`, `ray._private.object_ref_generator`, and
`ray._private.ray_logging.logging_config`. Each describes existing
behavior, written from the code.

This PR is stacked on #67540, which applies the ruff `D212` and `D200`
auto-fixes to the same files, so the new docstrings follow that format
and the two PRs don't conflict. Review only the top commit. #67635
covers the rest of Ray Core.

## Before

Most `RuntimeEnv` and `RuntimeEnvConfig` methods had no docstring, and
several exception classes and `ObjectRefGenerator` methods had no
docstring, no `Args:` entries for their constructor parameters, or no
`Returns:` section.

## After

- `RuntimeEnv`: `set`, `serialize`, `deserialize`, `to_dict`, and every
field accessor, such as `working_dir`, `pip_config`, `conda_uri`,
`py_container_image`, and `plugins`, are documented, including what each
returns when its field isn't set.
- `RuntimeEnvConfig`: `parse_and_validate_runtime_env_config`,
`default_config`, and `to_dict` are documented.
- `RayError.to_bytes`, the `RayActorError.preempted` and
`actor_init_failed` properties, and the constructor parameters of
`RayActorError`, `AuthenticationError`, `TaskUnschedulableError`, and
`ActorUnschedulableError` are documented.
`RayTaskError.make_dual_exception_instance` has a `Returns:` section.
- `ObjectRefGenerator` documents its constructor parameters, `close`,
and `aclose`, and `completed`, `next_ready`, and `is_finished` have
`Returns:` sections.
- `LoggingConfig.to_dict` and `from_dict` have `Args:` and `Returns:`
sections.

This PR also fixes two swapped `#:` attribute comments in
`RayActorError.__init__`: the comment for `error_msg` described
`actor_init_failed`, and the other way around. Autodoc renders `#:`
comments as attribute docs.

Behavior is unchanged. The diff touches only docstrings and comments,
which the guard below confirms.

## Not in this PR

- `RuntimeEnvConfig.from_proto` and `build_proto_runtime_env_config`
convert to and from the protobuf message, which looks like internal
plumbing rather than public API. Should they stay on the public surface?
Making them private isn't a docstring-only change, so this PR leaves
them alone.
- `LoggingConfig` already has a class docstring, assigned through
`LoggingConfig.__doc__` after the class body. A docstring in the class
body would be overwritten, so nothing changes there.
- `ObjectRefGenerator.send`, `throw`, `asend`, and `athrow`,
`RayError.from_bytes` and `from_ray_exception`, `RuntimeEnv.get` and
`get_extension`, and the constructor parameters of `CrossLanguageError`,
`RayTaskError`, `RaySystemError`, `OutOfMemoryError`, and
`NodeDiedError` have parameters with no type hint. Ray's pydoclint
config rejects an `Args:` section until every parameter has a hint, so
they need a separate PR that adds the hints and the docstrings together.

## For reviewers

These are worth a close read:

- `RuntimeEnv.has_conda` is annotated `-> str` but returns a bool, and
`conda_env_name` and `conda_config` are annotated `-> str` but can
return None. The docstrings describe what the code returns. Fixing the
annotations is a code change for a separate PR.
- `RuntimeEnv.conda_uri`, `pip_uri`, and `uv_uri` describe the URI as a
hash of the environment spec, from the `get_uri` helpers in
`ray._private.runtime_env`. `conda_uri` returns None when `conda` names
an existing environment.
- `RuntimeEnv.deserialize` notes that it skips validation, and
`serialize` that it validates first, as the code does.

## Duplicate check

No open PR documents these symbols. I searched open PRs for the module
and method names. #67540, which this PR stacks on, touches the same
files for docstring format only.

## Testing

- `python ci/ray_ci/doc/check_docstring_only.py --base
upstream/doc-1903-core-docstring-autofix`: `docstring-only guard: 4
file(s), docstrings only.`
- The full pre-commit suite on the changed files, including ruff, black,
pydoclint, and the docstyle hook: passed.
- `uvx [email protected] check --select D212,D200,D210` on the changed files:
passed, so the new docstrings don't add work for the ruff config PR.
- The commit carries an `@rtd-build` line, so the Read the Docs preview
renders the changed docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 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]>
Base automatically changed from doc-1919-core-runtime-env-docstrings to master November 3, 2026 14:24
dstrodtman added a commit that referenced this pull request Nov 3, 2026
…can be documented (#67636)

## Summary

Adds type hints to public Ray Core signatures that have none, and
documents their parameters in the same change. Ray's pydoclint config
rejects an `Args:` section until every parameter has a type hint, so
these symbols couldn't be documented in the docstring-only PRs. This PR
also corrects five return annotations that didn't match what the
functions return, and documents `ray.util.tpu.dispatch`.

This PR is stacked on #67635, which is stacked on #67634. Those two PRs
document the rest of these files. Review only the top two commits. It
isn't labeled `docstring-only`, because the signatures change, so it
runs the full Core premerge.

## What changes

Type hints and docstrings:

- `ObjectRefGenerator.send`, `throw`, `asend`, and `athrow`: `value:
Any`. Each method only raises `NotImplementedError`, and the docstrings
say so.
- `RayError.from_bytes(b: bytes) -> BaseException` and
`from_ray_exception(ray_exception: RayException) -> BaseException`.
- The constructors of `CrossLanguageError`, `RayTaskError`,
`RaySystemError`, `OutOfMemoryError`, and `NodeDiedError`.
- `RuntimeContext.__init__(worker: Any)`. The worker is either the
global Ray worker or Ray Client's `_ClientWorkerPropertyAPI`, which
emulates it, so `Any` is the honest hint without new imports.
- `RuntimeEnv.get(name: str, default: Any = None, data_class:
Optional[type] = None) -> Any` and `get_extension(key: str)`.

Return annotations corrected to match the code:

- `RuntimeEnv.has_conda`: `str` to `bool`.
- `RuntimeEnv.conda_env_name` and `conda_config`: `str` to
`Optional[str]`. Both return None when `conda` isn't set or has the
other form.
- `RuntimeEnv.py_container_run_options`: `List` to `Optional[List]`. It
returns None when `container` isn't set.
- `ray.util.list_named_actors`: `List[str]` to `Union[List[str],
List[Dict[str, str]]]`. With `all_namespaces=True`, it returns dicts
with `name` and `namespace` keys.

Docstring only:

- `ray.util.tpu.dispatch`, the deprecated alias of `run_on_slice`, gets
`Args:` and `Returns:` sections. Adding `Returns:` makes pydoclint check
`*args` and `**kwargs`, so they're documented too. CODEOWNERS assigns
`util/tpu.py` to `@andrewsykim`, `@edoakes`, and `@ryanaoleary`, so this
PR needs one of them in addition to ray-core.

Type hints don't change runtime behavior. None of these files are in
Ray's mypy hook.

## For reviewers

These are worth a close read:

- `RayTaskError.cause` is hinted `BaseException`, which matches what the
task-execution path in `_raylet.pyx` and `CompiledDAG` pass. `actor_id`
is the actor ID in hex, as `_raylet.pyx` computes it.
- `RaySystemError.client_exc` is hinted `str`. The callers in
`worker.py`, `serialization.py`, and `_raylet.pyx` pass a message
string, despite the parameter name.
- `RayError.from_bytes` and `from_ray_exception` return `BaseException`:
an unpickled exception, an `UnserializableException`, or a
`CrossLanguageError`.

`ray.util.client.api.ClientAPI.list_named_actors` carries the same
`List[str]` annotation for Ray Client. It isn't public API, so this PR
leaves it alone.

## Duplicate check

No open PR changes these signatures. I searched open PRs for the class
and method names.

## Testing

- The full pre-commit suite, including ruff, black, pydoclint, and the
docstyle hook, on every changed file, including `util/__init__.py` and
`util/tpu.py`: passed.
- `uvx [email protected] check --select D212,D200,D210` on the changed files:
passed.
- A smoke test against the latest nightly wheel with the four changed
files overlaid: a task error and an actor task error round-trip through
`to_bytes` and `from_bytes`, `ray.get_runtime_context()` works in the
driver and in an actor, the exception constructors format their
messages, `RuntimeEnv.get`, `get_extension`, and the re-annotated
accessors return what their annotations now say, and the streaming
generator's `send`, `throw`, `asend`, and `athrow` raise
`NotImplementedError`.
- `python/ray/tests/unit/test_runtime_env.py` and
`test_runtime_env_validation.py` against the same overlay: 96 passed, 12
failed. The same 12 fail with master's versions of the four files in the
same environment, because the nightly wheel's commit and the copied test
fixtures don't match this checkout, so none come from this change.
- The commit carries an `@rtd-build` line, so the Read the Docs preview
renders the changed docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 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]>
@dstrodtman
dstrodtman requested a review from a team as a code owner November 3, 2026 14:25
dstrodtman and others added 2 commits November 3, 2026 10:04
…erimental, and the actor and remote function APIs

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
…can be documented (#67636)

## Summary

Adds type hints to public Ray Core signatures that have none, and
documents their parameters in the same change. Ray's pydoclint config
rejects an `Args:` section until every parameter has a type hint, so
these symbols couldn't be documented in the docstring-only PRs. This PR
also corrects five return annotations that didn't match what the
functions return, and documents `ray.util.tpu.dispatch`.

This PR is stacked on #67635, which is stacked on #67634. Those two PRs
document the rest of these files. Review only the top two commits. It
isn't labeled `docstring-only`, because the signatures change, so it
runs the full Core premerge.

## What changes

Type hints and docstrings:

- `ObjectRefGenerator.send`, `throw`, `asend`, and `athrow`: `value:
Any`. Each method only raises `NotImplementedError`, and the docstrings
say so.
- `RayError.from_bytes(b: bytes) -> BaseException` and
`from_ray_exception(ray_exception: RayException) -> BaseException`.
- The constructors of `CrossLanguageError`, `RayTaskError`,
`RaySystemError`, `OutOfMemoryError`, and `NodeDiedError`.
- `RuntimeContext.__init__(worker: Any)`. The worker is either the
global Ray worker or Ray Client's `_ClientWorkerPropertyAPI`, which
emulates it, so `Any` is the honest hint without new imports.
- `RuntimeEnv.get(name: str, default: Any = None, data_class:
Optional[type] = None) -> Any` and `get_extension(key: str)`.

Return annotations corrected to match the code:

- `RuntimeEnv.has_conda`: `str` to `bool`.
- `RuntimeEnv.conda_env_name` and `conda_config`: `str` to
`Optional[str]`. Both return None when `conda` isn't set or has the
other form.
- `RuntimeEnv.py_container_run_options`: `List` to `Optional[List]`. It
returns None when `container` isn't set.
- `ray.util.list_named_actors`: `List[str]` to `Union[List[str],
List[Dict[str, str]]]`. With `all_namespaces=True`, it returns dicts
with `name` and `namespace` keys.

Docstring only:

- `ray.util.tpu.dispatch`, the deprecated alias of `run_on_slice`, gets
`Args:` and `Returns:` sections. Adding `Returns:` makes pydoclint check
`*args` and `**kwargs`, so they're documented too. CODEOWNERS assigns
`util/tpu.py` to `@andrewsykim`, `@edoakes`, and `@ryanaoleary`, so this
PR needs one of them in addition to ray-core.

Type hints don't change runtime behavior. None of these files are in
Ray's mypy hook.

## For reviewers

These are worth a close read:

- `RayTaskError.cause` is hinted `BaseException`, which matches what the
task-execution path in `_raylet.pyx` and `CompiledDAG` pass. `actor_id`
is the actor ID in hex, as `_raylet.pyx` computes it.
- `RaySystemError.client_exc` is hinted `str`. The callers in
`worker.py`, `serialization.py`, and `_raylet.pyx` pass a message
string, despite the parameter name.
- `RayError.from_bytes` and `from_ray_exception` return `BaseException`:
an unpickled exception, an `UnserializableException`, or a
`CrossLanguageError`.

`ray.util.client.api.ClientAPI.list_named_actors` carries the same
`List[str]` annotation for Ray Client. It isn't public API, so this PR
leaves it alone.

## Duplicate check

No open PR changes these signatures. I searched open PRs for the class
and method names.

## Testing

- The full pre-commit suite, including ruff, black, pydoclint, and the
docstyle hook, on every changed file, including `util/__init__.py` and
`util/tpu.py`: passed.
- `uvx [email protected] check --select D212,D200,D210` on the changed files:
passed.
- A smoke test against the latest nightly wheel with the four changed
files overlaid: a task error and an actor task error round-trip through
`to_bytes` and `from_bytes`, `ray.get_runtime_context()` works in the
driver and in an actor, the exception constructors format their
messages, `RuntimeEnv.get`, `get_extension`, and the re-annotated
accessors return what their annotations now say, and the streaming
generator's `send`, `throw`, `asend`, and `athrow` raise
`NotImplementedError`.
- `python/ray/tests/unit/test_runtime_env.py` and
`test_runtime_env_validation.py` against the same overlay: 96 passed, 12
failed. The same 12 fail with master's versions of the four files in the
same environment, because the nightly wheel's commit and the copied test
fixtures don't match this checkout, so none come from this change.
- The commit carries an `@rtd-build` line, so the Read the Docs preview
renders the changed docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 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]>
@dstrodtman
dstrodtman force-pushed the doc-1919-core-util-docstrings branch from 746bf1b to 5f40e2f Compare November 3, 2026 15:04
@dstrodtman dstrodtman changed the title [core] Add missing docstrings, Args, and Returns to ray.util, ray.experimental, and the actor APIs [core] Add missing docstrings, and type hints where documenting needs them, to Ray Core public APIs Nov 3, 2026
@dstrodtman dstrodtman removed the docstring-only Skip heavy library tests for Ray API docstring edits. label Nov 3, 2026
@edoakes
edoakes merged commit 6357e3c into master Nov 3, 2026
4 of 6 checks passed
@edoakes
edoakes deleted the doc-1919-core-util-docstrings branch November 3, 2026 18:16
pawelbeza pushed a commit to pawelbeza/ray that referenced this pull request Nov 9, 2026
… them, to Ray Core public APIs (ray-project#67635)

## Summary

Documents the public Ray Core symbols that are still missing docstrings,
`Args:` entries, or `Returns:` sections in `ray.util`, `ray.util.queue`,
`ray.util.spark`, `ray.util.tpu`, `ray.experimental`, `ray.actor`,
`ray.remote_function`, `ray.types`, `ray.exceptions`, `ray.runtime_env`,
`ray.runtime_context`, and `ObjectRefGenerator`. Each docstring
describes existing behavior, written from the code.

Some of these symbols couldn't be documented without a signature change.
Ray's pydoclint config rejects an `Args:` section until every parameter
has a type hint, so this PR also adds type hints to the untyped public
signatures it documents. It also corrects five return annotations that
didn't match what the functions return.

ray-project#67540 applied the ruff `D212` and `D200` auto-fixes to these files, and
ray-project#67634 documented `ray.runtime_env`, `ray.exceptions`, and
`ObjectRefGenerator`. Both are merged. This PR builds on them and has
two commits: the docstring additions, then the type annotations. The
second commit was reviewed as ray-project#67636, which merged into this branch
instead of `master`.

Because the signatures change, this PR isn't docstring-only and runs the
full Core premerge.

## Docstrings

- `ray.util.queue`: `Empty` and `Full` are documented, and `Queue.size`,
`qsize`, `empty`, and `full` have `Returns:` sections.
- `ray.util.list_named_actors` documents `all_namespaces` and returns,
including the dict entries it returns when `all_namespaces` is True.
- `ray.util.spark.setup_global_ray_cluster` documents all 17 parameters
and what it returns. Most entries follow the matching
`setup_ray_cluster` parameter, which the existing docstring already says
they share, and point to it for defaults and caps.
- `ray.util.tpu.dispatch`, the deprecated alias of `run_on_slice`, gets
`Args:` and `Returns:` sections. Adding `Returns:` makes pydoclint check
`*args` and `**kwargs`, so they're documented too.
- `ray.experimental`: `CompiledDAGRef.get` and the `CompiledDAGFuture`
constructor parameters, the `RayActorHandleResolver` constructor and its
`get`, `forget`, `list_names`, and `kill` methods, and the `ReduceOp`,
`AllGatherOp`, `AllReduceOp`, `ReduceScatterOp`, and `Device` types are
documented.
- `ActorMethod.__call__` and `remote`, `ActorClassInheritanceException`,
`RemoteFunction.__call__`, and `ray.types.ObjectRef` have docstrings.

## Type hints

Type hints added, with the parameters documented in the same change:

- `ObjectRefGenerator.send`, `throw`, `asend`, and `athrow`: `value:
Any`. Each method only raises `NotImplementedError`, and the docstrings
say so.
- `RayError.from_bytes(b: bytes) -> BaseException` and
`from_ray_exception(ray_exception: RayException) -> BaseException`.
- The constructors of `CrossLanguageError`, `RayTaskError`,
`RaySystemError`, `OutOfMemoryError`, and `NodeDiedError`.
- `RuntimeContext.__init__(worker: Any)`. The worker is either the
global Ray worker or Ray Client's `_ClientWorkerPropertyAPI`, which
emulates it, so `Any` is the honest hint without new imports.
- `RuntimeEnv.get(name: str, default: Any = None, data_class:
Optional[type] = None) -> Any` and `get_extension(key: str)`.

Return annotations corrected to match the code:

- `RuntimeEnv.has_conda`: `str` to `bool`.
- `RuntimeEnv.conda_env_name` and `conda_config`: `str` to
`Optional[str]`. Both return None when `conda` isn't set or has the
other form.
- `RuntimeEnv.py_container_run_options`: `List` to `Optional[List]`. It
returns None when `container` isn't set.
- `ray.util.list_named_actors`: `List[str]` to `Union[List[str],
List[Dict[str, str]]]`. With `all_namespaces=True`, it returns dicts
with `name` and `namespace` keys.

`AsyncioRouter` in `python/ray/serve/_private/router.py` reads
`RayTaskError.cause` into a local variable before the `ActorDiedError`
check instead of calling `getattr` in the condition. It returns the same
value in the same cases.

Type hints don't change runtime behavior. None of these files are in
Ray's mypy hook.

## For reviewers

CODEOWNERS adds two reviewers beyond `@ray-project/ray-core`:
`@ray-project/ray-serve` for `serve/_private/router.py`, and one of the
individual owners of `util/tpu.py`.

These are worth a close read:

- `setup_global_ray_cluster` returns the `(address,
remote_connection_address)` tuple only when `is_blocking` is False. When
blocking, it returns None after the cluster shuts down.
- `CompiledDAGRef.get` describes the `timeout` values from
`CompiledDAG._execute_until`, which it calls. `ray.get()` on a
CompiledDAGRef calls this method.
- `Device` describes its members from the `device` argument of
`TorchTensorType`.
- `RayTaskError.cause` is hinted `BaseException`, which matches what the
task-execution path in `_raylet.pyx` and `CompiledDAG` pass. `actor_id`
is the actor ID in hex, as `_raylet.pyx` computes it.
- `RaySystemError.client_exc` is hinted `str`. The callers in
`worker.py`, `serialization.py`, and `_raylet.pyx` pass a message
string, despite the parameter name.
- `RayError.from_bytes` and `from_ray_exception` return `BaseException`:
an unpickled exception, an `UnserializableException`, or a
`CrossLanguageError`.

`ray.util.client.api.ClientAPI.list_named_actors` has the same
`List[str]` annotation for Ray Client. It isn't public API, so this PR
leaves it alone.

## Duplicate check

No open PR documents these symbols or changes these signatures. I
searched open PRs for the module, class, and method names. ray-project#66745
converts the `Queue` class docstring example to doctest form, which
doesn't overlap the lines this PR changes.

## Testing

These checks ran on each commit before the rebase onto `master`. The
rebase applied both commits unchanged.

- The full pre-commit suite on every changed file, including ruff,
black, pydoclint, and the docstyle hook: passed.
- `uvx [email protected] check --select D212,D200,D210` on the changed files:
passed.
- The docstring commit passed `ci/ray_ci/doc/check_docstring_only.py`.
The type-annotation commit changes signatures, so it's outside that
guard by design.
- A smoke test against the latest nightly wheel with the type-annotated
files overlaid: a task error and an actor task error round-trip through
`to_bytes` and `from_bytes`, `ray.get_runtime_context()` works in the
driver and in an actor, the exception constructors format their
messages, `RuntimeEnv.get`, `get_extension`, and the re-annotated
accessors return what their annotations now say, and the streaming
generator's `send`, `throw`, `asend`, and `athrow` raise
`NotImplementedError`.
- `python/ray/tests/unit/test_runtime_env.py` and
`test_runtime_env_validation.py` against the same overlay: 96 passed, 12
failed. The same 12 fail with `master`'s versions of those files in the
same environment, because the nightly wheel's commit and the copied test
fixtures don't match this checkout, so none come from this change.
- Both commits carry an `@rtd-build` line, so the Read the Docs preview
renders the changed docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 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]>
Signed-off-by: Pawel Beza <[email protected]>
Upstream-commit: 6357e3c (sandbox resolver only; unrelated API changes excluded)
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0baa3cf-af4e-472e-ad89-8f02c6e8be11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants