-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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] add type hints for controller and backend_worker #10288
[Serve] add type hints for controller and backend_worker #10288
Conversation
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.
LGTM with two minor things
python/ray/serve/backend_worker.py
Outdated
backend_config: BackendConfig, | ||
instance_name=None): | ||
instance_name: str = None): |
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.
Optional[str]
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.
Good catch, fixed
@@ -140,7 +141,7 @@ def wrap_to_ray_error(exception): | |||
return ray.exceptions.RayTaskError(str(e), traceback_str, e.__class__) | |||
|
|||
|
|||
def ensure_async(func): | |||
def ensure_async(func: Callable) -> Callable: |
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.
-> AsyncCallable
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.
Couldn't find AsyncCallable in the project or on google, I made it Coroutine instead
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.
Oops. Sorry I confused types in typing
and those in inspect
. Coroutine
is not actually correct. Coroutine
are things you get after call call an async
func and it can be awaited on. We are typing async
in this case. Can we just revert the change, back to Callable
?
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.
No problem, done
The CI is failing because of some bug with pickle not being able to pickle Union[str, None]. According to facebookresearch/hydra#428 this is fixed in a new version of cloudpickle. What should we do here? |
Thanks for tracking this down. Let's drop the type hints in |
python/ray/serve/api.py
Outdated
@@ -56,7 +56,8 @@ def __call__(self, *, python_arg=None): | |||
return f | |||
|
|||
|
|||
def init(name: Optional[str] = None, | |||
# TODO(architkulkarni): Add type hint for name after upgrading cloudpickle. |
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 is fine. I think cloudpickle only breaks for Optional
in generated class like RayServeWrappedWorker
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.
I see, that makes sense. I forgot that the tests for the type hints for API were passing earlier. I'll revert this change
python/ray/serve/controller.py
Outdated
async def create_endpoint( | ||
self, endpoint: str, traffic_dict: Dict[str, float], | ||
route: Optional[str], methods: List[str]) -> None: |
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 is where the build error come from.
Why are these changes needed?
Adds type hints for
controller.py
andbackend_worker.py
Related issue number
Checks
scripts/format.sh
to lint the changes in this PR.