Skip to content

Commit

Permalink
fixed remote decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Oct 5, 2022
1 parent 7cf94e5 commit 4a07a22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions pymargo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,9 @@ def config(self) -> dict:
return json.loads(config_str)


def remote(rpc_name: Optional[str] = None,
disable_response: Optional[bool] = False,
service_name: Optional[str] = None):
"""
Decorator that adds information to a function to tell
pymargo how it should be registeted as an RPC.
"""
def _remote(rpc_name: Optional[str] = None,
disable_response: Optional[bool] = False,
service_name: Optional[str] = None):
def decorator(func):
name = rpc_name
if name is None:
Expand All @@ -647,6 +643,19 @@ def decorator(func):
return decorator


def remote(*args, **kwargs):
"""
Decorator that adds information to a function to tell
pymargo how it should be registeted as an RPC.
"""
if len(args) == 1 and callable(args[0]):
# @remote
return _remote()(args[0])
else:
# @remote(...)
return _remote(*args, **kwargs)


def provider(service_name: Optional[str] = None):
"""
Decorator that adds information to a class to tell
Expand Down
2 changes: 1 addition & 1 deletion pymargo/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MyProvider:
def hello_world(self, handle):
handle.respond('Hello World')

@remote()
@remote
def hello_someone(self, handle, firstname, lastname):
handle.respond(f'Hello {firstname} {lastname}')

Expand Down

0 comments on commit 4a07a22

Please sign in to comment.