Skip to content

Commit 814d48d

Browse files
zdevitofacebook-github-bot
authored andcommitted
Fix non-async endpoint type checking (#510)
Summary: Pull Request resolved: #510 It wasn't working correctly if the function didn't return an Awaitable. Reviewed By: suo Differential Revision: D78181976 fbshipit-source-id: da11cec3c896b97290fac2d652fd41c3c55b7108
1 parent 3103920 commit 814d48d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

python/monarch/_src/actor/actor_mesh.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Literal,
3535
NamedTuple,
3636
Optional,
37+
overload,
3738
ParamSpec,
3839
Sequence,
3940
Tuple,
@@ -466,7 +467,13 @@ def send(
466467

467468

468469
class EndpointProperty(Generic[P, R]):
469-
def __init__(self, method: Callable[Concatenate[Any, P], Awaitable[R]]) -> None:
470+
@overload
471+
def __init__(self, method: Callable[Concatenate[Any, P], Awaitable[R]]) -> None: ...
472+
473+
@overload
474+
def __init__(self, method: Callable[Concatenate[Any, P], R]) -> None: ...
475+
476+
def __init__(self, method: Any) -> None:
470477
self._method = method
471478

472479
def __get__(self, instance, owner) -> Endpoint[P, R]:
@@ -476,9 +483,19 @@ def __get__(self, instance, owner) -> Endpoint[P, R]:
476483
return cast(Endpoint[P, R], self)
477484

478485

486+
@overload
479487
def endpoint(
480488
method: Callable[Concatenate[Any, P], Awaitable[R]],
481-
) -> EndpointProperty[P, R]:
489+
) -> EndpointProperty[P, R]: ...
490+
491+
492+
@overload
493+
def endpoint(
494+
method: Callable[Concatenate[Any, P], R],
495+
) -> EndpointProperty[P, R]: ...
496+
497+
498+
def endpoint(method):
482499
return EndpointProperty(method)
483500

484501

0 commit comments

Comments
 (0)