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

mypy doesn not recognise that classes annotated with @serve.deployment should have a bind method. #40018

Open
JakeSummers opened this issue Oct 2, 2023 · 2 comments
Labels
bug Something that is supposed to be working; but isn't P2 Important issue, but not time-critical serve Ray Serve Related Issue

Comments

@JakeSummers
Copy link

What happened + What you expected to happen

Given this code:

from ray import serve


@serve.deployment(num_replicas=2, ray_actor_options={"num_cpus": 0.2, "num_gpus": 0})
class SayHi:
    def __init__(self, greeting: str):
        # Load model
        self.message = greeting

    def say_hi(self, name: str) -> str:
        # Run inference
        model_output = f"{self.message} {name}"
        return model_output

    async def __call__(self, name: str) -> str:
        return self.say_hi(name)


hi_app = SayHi.bind("Hi") # <------------------- MYPY COMPLAINS HERE

And run:

mypy .

This raises the following error:

my_project/ray_serve/say_hi.py:19: error: "type[SayHi]" has no attribute "bind"  [attr-defined]

This should raise no error.

Versions / Dependencies

ray / ray[serve]

$ poetry show ray
 name         : ray
 version      : 2.7.0
 description  : Ray provides a simple, universal API for building distributed applications.

dependencies
 - aiohttp >=3.7
 - aiohttp-cors *
 - aiorwlock *
 - aiosignal *
 - click >=7.0
 - colorful *
 - fastapi *
 - filelock *
 - frozenlist *
 - gpustat >=1.0.0
 - grpcio >=1.32.0
 - grpcio >=1.42.0
 - jsonschema *
 - msgpack >=1.0.0,<2.0.0
 - numpy >=1.19.3
 - opencensus *
 - packaging *
 - prometheus-client >=0.7.1
 - protobuf >=3.15.3,<3.19.5 || >3.19.5
 - py-spy >=0.2.0
 - pydantic <2
 - pyyaml *
 - requests *
 - smart-open *
 - starlette *
 - uvicorn *
 - virtualenv >=20.0.24,<20.21.1
 - watchfiles *

mypy:

$ poetry show mypy
 name         : mypy
 version      : 1.5.1
 description  : Optional static typing for Python

dependencies
 - mypy-extensions >=1.0.0
 - tomli >=1.1.0
 - typing-extensions >=4.1.0

Reproduction script

See above section :)

Issue Severity

Medium: It is a significant difficulty but I can work around it.

@JakeSummers JakeSummers added bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Oct 2, 2023
@JakeSummers
Copy link
Author

This seems similar to #25657

@anyscalesam anyscalesam added the serve Ray Serve Related Issue label Oct 2, 2023
@shrekris-anyscale shrekris-anyscale added P2 Important issue, but not time-critical and removed triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Oct 16, 2023
@chasleslr
Copy link

This seems related to an ongoing Mypy limitation described here: python/mypy#3135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to be working; but isn't P2 Important issue, but not time-critical serve Ray Serve Related Issue
Projects
None yet
Development

No branches or pull requests

4 participants