Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6346f5

Browse files
committed
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: 0rpc#239 Signed-off-by: Cedric Hombourger <[email protected]>
1 parent 3d0a6ee commit d6346f5

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

tests/test_client_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def add(self, a, b):
5353
client = zerorpc.Client(timeout=TIME_FACTOR * 2)
5454
client.connect(endpoint)
5555

56-
async_result = client.add(1, 4, async=True)
56+
async_result = client.add(1, 4, async_=True)
5757

5858
if sys.version_info < (2, 7):
5959
def _do_with_assert_raises():
@@ -84,8 +84,8 @@ def add(self, a, b):
8484
client = zerorpc.Client()
8585
client.connect(endpoint)
8686

87-
async_result = client.lolita(async=True)
87+
async_result = client.lolita(async_=True)
8888
assert async_result.get() == 42
8989

90-
async_result = client.add(1, 4, async=True)
90+
async_result = client.add(1, 4, async_=True)
9191
assert async_result.get() == 5

zerorpc/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ def __call__(self, method, *args, **kargs):
266266
self._context.hook_client_before_request(request_event)
267267
bufchan.emit_event(request_event)
268268

269-
if kargs.get('async', False) is False:
269+
# In python 3.7, "async" is a reserved keyword, clients should now use
270+
# "async_": support both for the time being
271+
if (kargs.get('async', False) is False and
272+
kargs.get('async_', False) is False):
270273
return self._process_response(request_event, bufchan, timeout)
271274

272275
async_result = gevent.event.AsyncResult()

0 commit comments

Comments
 (0)