A quick example, using Ray:
import ray
ray.init()
@ray.remote
def do_things(x: int, y: float):
return x * y
@ray.remote
def do_more_things(name: str, value: float):
return f"{name}: {value}"
pure_value = do_things(x=3, y=2.2) # pure_value is type: float
ref_value = do_things.remote(x=3, y=2.2) # ref_value is type: ObjectRef[float]
pure_second_value = do_more_things(name="Foo", value=pure_value) # this is fine
ref_second_value = do_more_things.remote(name="Foo", value=ref_value) # this should be fine
So, do_things()
and do_more_things()
should keep their signature. But their remote
counterparts should have a signature that allows the original types or a wrapper ObjectRef[OriginalType]
for each argument:
do_things.remote(x: int | ObjectRef[int], y: float | ObjectRef[float]) -> ObjectRef[float]: ...
do_more_things.remote(name: str | ObjectRef[str], value: float | ObjectRef[float]) -> ObjectRef[str]: ...
Now, I know type annotating this in this particular API design is probably difficult, and possibly not easily supported yet. I was thinking of an alternative API that could take advantage of ParamSpec
, TypeVar
s with overload
s and/or TypeVarTuple
. But I still can't find a way to get all the desired features together.
Longer discussion and ideas I tried: https://github.com/python/typing/discussions/1163
---
Assuming this is currently not possible, what would be needed to make it possible? Would some way of achieving this be acceptable?
And if so, what would be the best approach to make it possible?
I'm not sure what's the process, but maybe there could be a way to sponsor someone with the right expertise here to tackle it, I imagine it would require a PEP, work on mypy, not sure what else, but maybe I'm being naive in some way and it would require a different approach.
Thanks for your help and ideas/feedback!
Sebastián