Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serve] Allow methods to pass type @serve.batch type hint #45004

Merged

Conversation

shrekris-anyscale
Copy link
Contributor

Why are these changes needed?

Without this change, mypy raises a type warning when decorating methods with @serve.batch:

Screenshot 2024-04-26 at 5 14 00 PM

With this change, mypy no longer raises a type warning for methods:

Screenshot 2024-04-26 at 5 14 35 PM

We should be aware that functions with an extra parameter before the input list will now pass the type check. This allows users to define a method outside a class and then assign it to a class:

Screenshot 2024-04-26 at 5 17 30 PM

Related issue number

N/A

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • This change relies on existing tests.

Signed-off-by: Shreyas Krishnaswamy <shrekris@anyscale.com>
Copy link
Contributor

@edoakes edoakes left a comment

Choose a reason for hiding this comment

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

thx!

@edoakes edoakes merged commit e3fb472 into ray-project:master Apr 29, 2024
5 checks passed
@shrekris-anyscale shrekris-anyscale self-assigned this Apr 30, 2024
harborn pushed a commit to harborn/ray that referenced this pull request May 8, 2024
…ect#45004)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

<!-- Please give a short summary of the change and the problem this
solves. -->

Without this change, `mypy` raises a type warning when decorating
methods with `@serve.batch`:

<img width="504" alt="Screenshot 2024-04-26 at 5 14 00 PM"
src="https://github.com/ray-project/ray/assets/92341594/fd535d23-2a41-4f62-bb38-5f41a8bf53d5">

With this change, `mypy` no longer raises a type warning for methods:

<img width="505" alt="Screenshot 2024-04-26 at 5 14 35 PM"
src="https://github.com/ray-project/ray/assets/92341594/b14c4167-30e9-417e-a920-d694629b8038">

We should be aware that functions with an extra parameter before the
input list will now pass the type check. This allows users to define a
method outside a class and then assign it to a class:

<img width="329" alt="Screenshot 2024-04-26 at 5 17 30 PM"
src="https://github.com/ray-project/ray/assets/92341594/54043cf3-677a-48b8-a83b-10bec2ee6053">

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

N/A

## Checks

- [X] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [X] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - This change relies on existing tests.

Signed-off-by: Shreyas Krishnaswamy <shrekris@anyscale.com>
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Jun 7, 2024
…ect#45004)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

<!-- Please give a short summary of the change and the problem this
solves. -->

Without this change, `mypy` raises a type warning when decorating
methods with `@serve.batch`:

<img width="504" alt="Screenshot 2024-04-26 at 5 14 00 PM"
src="https://github.com/ray-project/ray/assets/92341594/fd535d23-2a41-4f62-bb38-5f41a8bf53d5">

With this change, `mypy` no longer raises a type warning for methods:

<img width="505" alt="Screenshot 2024-04-26 at 5 14 35 PM"
src="https://github.com/ray-project/ray/assets/92341594/b14c4167-30e9-417e-a920-d694629b8038">

We should be aware that functions with an extra parameter before the
input list will now pass the type check. This allows users to define a
method outside a class and then assign it to a class:

<img width="329" alt="Screenshot 2024-04-26 at 5 17 30 PM"
src="https://github.com/ray-project/ray/assets/92341594/54043cf3-677a-48b8-a83b-10bec2ee6053">

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

N/A

## Checks

- [X] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [X] I've run `scripts/format.sh` to lint the changes in this PR.
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - This change relies on existing tests.

Signed-off-by: Shreyas Krishnaswamy <shrekris@anyscale.com>
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.

None yet

2 participants