From d6346f5687d235acdd2f4eec10acc7cfeb8ba572 Mon Sep 17 00:00:00 2001 From: Cedric Hombourger Date: Wed, 5 Jan 2022 21:05:09 +0100 Subject: [PATCH] core: handle both "async" and "async_" in remote calls Python 3.7 made "async" a reserved keyword: this causes a syntax error when passing "async" as a named parameter in remote procedure calls. Make ClientBase.__call__() understand both "async" and "async_" so we don't break our binary interface with older clients. Fixes: #239 Signed-off-by: Cedric Hombourger --- tests/test_client_async.py | 6 +++--- zerorpc/core.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_client_async.py b/tests/test_client_async.py index 3acbd3b..6ce4def 100644 --- a/tests/test_client_async.py +++ b/tests/test_client_async.py @@ -53,7 +53,7 @@ def add(self, a, b): client = zerorpc.Client(timeout=TIME_FACTOR * 2) client.connect(endpoint) - async_result = client.add(1, 4, async=True) + async_result = client.add(1, 4, async_=True) if sys.version_info < (2, 7): def _do_with_assert_raises(): @@ -84,8 +84,8 @@ def add(self, a, b): client = zerorpc.Client() client.connect(endpoint) - async_result = client.lolita(async=True) + async_result = client.lolita(async_=True) assert async_result.get() == 42 - async_result = client.add(1, 4, async=True) + async_result = client.add(1, 4, async_=True) assert async_result.get() == 5 diff --git a/zerorpc/core.py b/zerorpc/core.py index 9fa63e3..9dbf5cc 100644 --- a/zerorpc/core.py +++ b/zerorpc/core.py @@ -266,7 +266,10 @@ def __call__(self, method, *args, **kargs): self._context.hook_client_before_request(request_event) bufchan.emit_event(request_event) - if kargs.get('async', False) is False: + # In python 3.7, "async" is a reserved keyword, clients should now use + # "async_": support both for the time being + if (kargs.get('async', False) is False and + kargs.get('async_', False) is False): return self._process_response(request_event, bufchan, timeout) async_result = gevent.event.AsyncResult()