Skip to content

[serve] Clean up API reference and various docstrings - #34711

Merged
edoakes merged 33 commits into
ray-project:masterfrom
edoakes:app-class-apiref
May 5, 2023
Merged

edoakes merged 33 commits into
ray-project:masterfrom
edoakes:app-class-apiref

Conversation

@edoakes

@edoakes edoakes commented Apr 24, 2023 •

Copy link
Copy Markdown
Collaborator

Why are these changes needed?

Cleans up the API reference page formatting, adds/updates docstrings where applicable (corrects typing + verbiage, adds inline examples).

Related issue number

Checks

Signed-off-by: Edward Oakes <[email protected]>
@edoakes edoakes changed the title [WIP][serve] API reference cleanups [serve] Clean up API reference and various docstrings Apr 25, 2023

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

LGTM!

Co-authored-by: Cindy Zhang <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
@edoakes

edoakes commented May 3, 2023

Copy link
Copy Markdown
Collaborator Author

@ray-project/ray-docs can I get a review on this please

Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/deployment.py Resolved
Comment thread python/ray/serve/deployment.py Resolved
Comment thread python/ray/serve/handle.py Resolved
Comment thread python/ray/serve/handle.py Resolved

<!---
NOTE: `serve.deployment` and `serve.Deployment` have an autosummary-generated filename collision due to case insensitivity.
This is fixed by added custom filename mappings in `source/conf.py` (look for "autosummary_filename_map").

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.

Suggested change
This is fixed by added custom filename mappings in `source/conf.py` (look for "autosummary_filename_map").
This is fixed by added custom filename mappings in `source/conf.py`. (Look for "autosummary_filename_map".)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually correct as-is?

Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Comment thread python/ray/serve/api.py
>>> # deployment_name#krcwoa
>>> serve.get_replica_context().replica_tag # doctest: +SKIP

.. code-block:: python

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.

eventually we will move off this code-block thing, fyi

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onto what?

Comment thread python/ray/serve/deployment.py Resolved
@angelinalg

Copy link
Copy Markdown
Contributor

Had some minor copy edits. Please use the Add suggestion to batch button if you want to batch the suggestions into a single commit. Hope that helps.

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

LGTM

@edoakes

edoakes commented May 5, 2023

Copy link
Copy Markdown
Collaborator Author

Thanks @angelinalg !!

Signed-off-by: Edward Oakes <[email protected]>
@edoakes
edoakes merged commit 13ba050 into ray-project:master May 5, 2023
architkulkarni pushed a commit to architkulkarni/ray that referenced this pull request May 16, 2023
)

Cleans up the API reference page formatting, adds/updates docstrings where applicable (corrects typing + verbiage, adds inline examples).

Co-authored-by: Cindy Zhang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
akyang-anyscale pushed a commit that referenced this pull request Oct 26, 2026
## Description

`serve.deployment` dispatches on whether `_func_or_class` is passed. Its
only return annotation is `Callable[[Callable], Deployment]`. A bare
`@serve.deployment` therefore types as the decorator it would return.
Every later `.bind()` or `.options()` call on it is a type error:

```
error: Cannot access attribute "bind" for class "FunctionType"
    Attribute "bind" is unknown (reportFunctionMemberAccess)
```

This adds two `@overload` signatures. A callable first argument returns
`Deployment`, with or without options. No callable returns the
decorator. The first overload also accepts the options, unlike the pair
removed in #34711. `serve.deployment(MyClass, num_replicas=2)` works at
runtime and now types as `Deployment` too.

`check_deployment_typing.py` covers the bare, called and direct-call
forms. It sits next to `check_handle_typing.py` and is registered in the
`mypy (ray serve)` and `pyrefly (ray serve)` hooks and in
`pyrefly-serve.toml`.

## Related issues

Fixes #52483

## Additional information

mypy (python/mypy#3135) and pyrefly ignore the return type of a class
decorator. For them this fixes functions and direct calls.
`@serve.deployment class X` still types as `type[X]` there. pyright
applies class decorators, so the reproduction script in #52483 now
reports 0 errors.

Not a duplicate: #52483 has no linked PR. `gh pr list --repo
ray-project/ray --state open --search "52483 in:body"` returns nothing.

Tests run. Each `master api.py` result is the same command with only
`api.py` reverted to master.

```
# mypy 1.7.0, flags and file set of the "mypy (ray serve)" hook
MYPYPATH=python mypy --no-site-packages --follow-imports=silent --ignore-missing-imports <69 hook files>
Success: no issues found in 69 source files      # master api.py: 7 errors, all in check_deployment_typing.py

# pyrefly 1.1.1
pyrefly check --config python/ray/serve/pyrefly-serve.toml python/ray/serve/tests/typing_files/check_deployment_typing.py
0 errors                                         # master api.py: 7 errors

# pyright 1.1.406, extraPaths = ["python"]
pyright python/ray/serve/tests/typing_files/check_deployment_typing.py
0 errors                                         # master api.py: 7 errors
pyright <reproduction script from #52483>
0 errors                                         # master api.py: 2 errors
```

Disclaimer: this PR was prepared with the assistance of an AI agent
(Claude Code). All code and test changes were reviewed by the author
before submission.

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants