Skip to content

Commit eecb0ff

Browse files
maint: upgrade async-related python syntax
coroutine functions are now declared with the 'async' keyword fixes hugapi#902
1 parent 7e97181 commit eecb0ff

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

hug/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ def _ensure_started(self):
631631
if async_handlers:
632632
loop = asyncio.get_event_loop()
633633
loop.run_until_complete(
634-
asyncio.gather(*[handler(self) for handler in async_handlers], loop=loop)
634+
asyncio.gather(*[handler(self) for handler in async_handlers])
635635
)
636636
for startup_handler in self.startup_handlers:
637637
if not startup_handler in async_handlers:

tests/test_coroutines.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def test_basic_call_coroutine():
3131
"""The most basic Happy-Path test for Hug APIs using async"""
3232

3333
@hug.call()
34-
@asyncio.coroutine
35-
def hello_world():
34+
async def hello_world():
3635
return "Hello World!"
3736

3837
assert loop.run_until_complete(hello_world()) == "Hello World!"
@@ -42,25 +41,22 @@ def test_nested_basic_call_coroutine():
4241
"""The most basic Happy-Path test for Hug APIs using async"""
4342

4443
@hug.call()
45-
@asyncio.coroutine
46-
def hello_world():
44+
async def hello_world():
4745
return getattr(asyncio, "ensure_future")(nested_hello_world())
4846

4947
@hug.local()
50-
@asyncio.coroutine
51-
def nested_hello_world():
48+
async def nested_hello_world():
5249
return "Hello World!"
5350

54-
assert loop.run_until_complete(hello_world()) == "Hello World!"
51+
assert loop.run_until_complete(hello_world()).result() == "Hello World!"
5552

5653

5754
def test_basic_call_on_method_coroutine():
5855
"""Test to ensure the most basic call still works if applied to a method"""
5956

6057
class API(object):
6158
@hug.call()
62-
@asyncio.coroutine
63-
def hello_world(self=None):
59+
async def hello_world(self=None):
6460
return "Hello World!"
6561

6662
api_instance = API()
@@ -79,8 +75,7 @@ def hello_world(self):
7975
api_instance = API()
8076

8177
@hug.call()
82-
@asyncio.coroutine
83-
def hello_world():
78+
async def hello_world():
8479
return api_instance.hello_world()
8580

8681
assert api_instance.hello_world() == "Hello World!"
@@ -94,8 +89,7 @@ class API(object):
9489
def __init__(self):
9590
hug.call()(self.hello_world_method)
9691

97-
@asyncio.coroutine
98-
def hello_world_method(self):
92+
async def hello_world_method(self):
9993
return "Hello World!"
10094

10195
api_instance = API()

tests/test_decorators.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,7 @@ def happens_on_startup(api):
15861586
happened_on_startup.append("non-async")
15871587

15881588
@hug.startup(api=hug_api)
1589-
@asyncio.coroutine
1590-
def async_happens_on_startup(api):
1589+
async def async_happens_on_startup(api):
15911590
happened_on_startup.append("async")
15921591

15931592
assert happens_on_startup in hug_api.startup_handlers

0 commit comments

Comments
 (0)