-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Objectref typestubbing #55566
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
Objectref typestubbing #55566
Conversation
Signed-off-by: minerharry <[email protected]>
Signed-off-by: minerharry <[email protected]>
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
@can-anyscale can you review? |
…bbing Signed-off-by: minerharry <[email protected]>
Signed-off-by: minerharry <[email protected]>
…bbing Signed-off-by: minerharry <[email protected]>
@minerharry Thanks for doing this! Could you update the PR description with more details including the issue and solution. |
Sure, done |
Signed-off-by: minerharry <[email protected]>
hi yes, not stale, still in my list of doing, sorry about this |
python/ray/includes/unique_ids.pyi
Outdated
def nil(cls:type[_PGID])->_PGID: ... | ||
|
||
|
||
_ID_TYPES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be used any more, I made a PR to remove it #56184, can you also remove it from this PR?
This PR looks overall good to me, I have a few formatting requests before we can merge it:
|
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
Signed-off-by: Philipp Moritz <[email protected]>
thanks @pcmoritz! Great points about formatting, and thanks for updating them. I'll go ahead and do the same to the other PR as well. (what's the last step for merging this? new here) |
Sounds great, thanks! I'll just do a few final checks on the typing and then will merge the PR, aiming to get it done later today :) |
I performed some tests now: import ray
@ray.remote
def f() -> int:
return 1
a = f.remote()
reveal_type(ray.get(a))
reveal_type(a)
reveal_type(a.redis_shard_hash())
reveal_type(a.task_id())
async def g():
await a
print("path", ray.__path__, ray.__version__) Running Without:
With:
|
<!-- 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? Adds proper type-stubbing for ObjectRef (and its cousins, ActorID, TaskID, etc). See ray-project#53591. The ray/includes .pxi files (and the _raylet.pxi) are inaccessible to type-checkers, so core ray objects like ObjectRef don't have proper code-completion. While the issue extends to many ray objects defined in includes/* and _raylet.pxi, notably ObjectRefGenerator and similar, this PR focuses just on unique_ids.pxi and object_ref.pxi. By adding python stub files, .pyi, that correspond to the .pxi files, this PR allows type-checkers to understand the contents of the cython files. Each .pyi file contains the signature of every class and method in the .pxi files to expose (though I went ahead and added every method for completeness). Also, I added a `__class_getitem__` method to ObjectRef in object_ref.pxi which mirrors how typing.Generic works, as multiple inheritance (which would be required for generic subclassing of BaseID) is not well supported in cython. This allows for runtime type-subscripting (e.g. ObjectRef[int]) without error and returns a proper annotated type. ## Related issue number Limited-scope version of ray-project#55066, just focusing on unique_ids.pxi and object_ref.pxi. Partially satisfies ray-project#53591. ## 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. - [x] I've included any doc changes needed for https://docs.ray.io/en/master/. - [x] 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. - [x] 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 - [ ] Unit tests - [ ] Release tests - [x] This PR is not tested :( --------- Signed-off-by: minerharry <[email protected]> Signed-off-by: Philipp Moritz <[email protected]> Co-authored-by: Philipp Moritz <[email protected]> Signed-off-by: sampan <[email protected]>
Why are these changes needed?
Adds proper type-stubbing for ObjectRef (and its cousins, ActorID, TaskID, etc). See #53591. The ray/includes .pxi files (and the _raylet.pxi) are inaccessible to type-checkers, so core ray objects like ObjectRef don't have proper code-completion. While the issue extends to many ray objects defined in includes/* and _raylet.pxi, notably ObjectRefGenerator and similar, this PR focuses just on unique_ids.pxi and object_ref.pxi. By adding python stub files, .pyi, that correspond to the .pxi files, this PR allows type-checkers to understand the contents of the cython files. Each .pyi file contains the signature of every class and method in the .pxi files to expose (though I went ahead and added every method for completeness).
Also, I added a
__class_getitem__
method to ObjectRef in object_ref.pxi which mirrors how typing.Generic works, as multiple inheritance (which would be required for generic subclassing of BaseID) is not well supported in cython. This allows for runtime type-subscripting (e.g. ObjectRef[int]) without error and returns a proper annotated type.Related issue number
Limited-scope version of #55066, just focusing on unique_ids.pxi and object_ref.pxi. Partially satisfies #53591.
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.