@@ -575,9 +575,8 @@ def zero_error(fut):
575575 def test_default_exc_handler_coro (self ):
576576 self .loop ._process_events = mock .Mock ()
577577
578- @asyncio .coroutine
579- def zero_error_coro ():
580- yield from asyncio .sleep (0.01 )
578+ async def zero_error_coro ():
579+ await asyncio .sleep (0.01 )
581580 1 / 0
582581
583582 # Test Future.__del__
@@ -723,8 +722,7 @@ def test_set_task_factory(self):
723722 class MyTask (asyncio .Task ):
724723 pass
725724
726- @asyncio .coroutine
727- def coro ():
725+ async def coro ():
728726 pass
729727
730728 factory = lambda loop , coro : MyTask (coro , loop = loop )
@@ -779,8 +777,7 @@ def test_create_task(self):
779777 class MyTask (asyncio .Task ):
780778 pass
781779
782- @asyncio .coroutine
783- def test ():
780+ async def test ():
784781 pass
785782
786783 class EventLoop (base_events .BaseEventLoop ):
@@ -830,8 +827,7 @@ def test_run_forever_keyboard_interrupt(self):
830827 # Python issue #22601: ensure that the temporary task created by
831828 # run_forever() consumes the KeyboardInterrupt and so don't log
832829 # a warning
833- @asyncio .coroutine
834- def raise_keyboard_interrupt ():
830+ async def raise_keyboard_interrupt ():
835831 raise KeyboardInterrupt
836832
837833 self .loop ._process_events = mock .Mock ()
@@ -849,8 +845,7 @@ def raise_keyboard_interrupt():
849845 def test_run_until_complete_baseexception (self ):
850846 # Python issue #22429: run_until_complete() must not schedule a pending
851847 # call to stop() if the future raised a BaseException
852- @asyncio .coroutine
853- def raise_keyboard_interrupt ():
848+ async def raise_keyboard_interrupt ():
854849 raise KeyboardInterrupt
855850
856851 self .loop ._process_events = mock .Mock ()
@@ -1070,9 +1065,7 @@ def test_create_connection_multiple_errors(self, m_socket):
10701065 class MyProto (asyncio .Protocol ):
10711066 pass
10721067
1073- @asyncio .coroutine
1074- def getaddrinfo (* args , ** kw ):
1075- yield from []
1068+ async def getaddrinfo (* args , ** kw ):
10761069 return [(2 , 1 , 6 , '' , ('107.6.106.82' , 80 )),
10771070 (2 , 1 , 6 , '' , ('107.6.106.82' , 80 ))]
10781071
@@ -1191,9 +1184,8 @@ def test_create_connection_no_host_port_sock(self):
11911184 self .assertRaises (ValueError , self .loop .run_until_complete , coro )
11921185
11931186 def test_create_connection_no_getaddrinfo (self ):
1194- @asyncio .coroutine
1195- def getaddrinfo (* args , ** kw ):
1196- yield from []
1187+ async def getaddrinfo (* args , ** kw ):
1188+ return []
11971189
11981190 def getaddrinfo_task (* args , ** kwds ):
11991191 return asyncio .Task (getaddrinfo (* args , ** kwds ), loop = self .loop )
@@ -1219,8 +1211,7 @@ def getaddrinfo_task(*args, **kwds):
12191211 OSError , self .loop .run_until_complete , coro )
12201212
12211213 def test_create_connection_multiple (self ):
1222- @asyncio .coroutine
1223- def getaddrinfo (* args , ** kw ):
1214+ async def getaddrinfo (* args , ** kw ):
12241215 return [(2 , 1 , 6 , '' , ('0.0.0.1' , 80 )),
12251216 (2 , 1 , 6 , '' , ('0.0.0.2' , 80 ))]
12261217
@@ -1247,8 +1238,7 @@ def bind(addr):
12471238
12481239 m_socket .socket .return_value .bind = bind
12491240
1250- @asyncio .coroutine
1251- def getaddrinfo (* args , ** kw ):
1241+ async def getaddrinfo (* args , ** kw ):
12521242 return [(2 , 1 , 6 , '' , ('0.0.0.1' , 80 )),
12531243 (2 , 1 , 6 , '' , ('0.0.0.2' , 80 ))]
12541244
@@ -1349,8 +1339,7 @@ def test_create_connection_service_name(self, m_socket):
13491339 self .loop .run_until_complete (coro )
13501340
13511341 def test_create_connection_no_local_addr (self ):
1352- @asyncio .coroutine
1353- def getaddrinfo (host , * args , ** kw ):
1342+ async def getaddrinfo (host , * args , ** kw ):
13541343 if host == 'example.com' :
13551344 return [(2 , 1 , 6 , '' , ('107.6.106.82' , 80 )),
13561345 (2 , 1 , 6 , '' , ('107.6.106.82' , 80 ))]
@@ -1488,11 +1477,10 @@ def test_create_server_empty_host(self):
14881477 # if host is empty string use None instead
14891478 host = object ()
14901479
1491- @asyncio .coroutine
1492- def getaddrinfo (* args , ** kw ):
1480+ async def getaddrinfo (* args , ** kw ):
14931481 nonlocal host
14941482 host = args [0 ]
1495- yield from []
1483+ return []
14961484
14971485 def getaddrinfo_task (* args , ** kwds ):
14981486 return asyncio .Task (getaddrinfo (* args , ** kwds ), loop = self .loop )
@@ -1854,9 +1842,10 @@ def test_accept_connection_exception(self, m_log):
18541842 MyProto , sock , None , None , mock .ANY , mock .ANY )
18551843
18561844 def test_call_coroutine (self ):
1857- @asyncio .coroutine
1858- def simple_coroutine ():
1859- pass
1845+ with self .assertWarns (DeprecationWarning ):
1846+ @asyncio .coroutine
1847+ def simple_coroutine ():
1848+ pass
18601849
18611850 self .loop .set_debug (True )
18621851 coro_func = simple_coroutine
@@ -1880,9 +1869,7 @@ def test_log_slow_callbacks(self, m_logger):
18801869 def stop_loop_cb (loop ):
18811870 loop .stop ()
18821871
1883- @asyncio .coroutine
1884- def stop_loop_coro (loop ):
1885- yield from ()
1872+ async def stop_loop_coro (loop ):
18861873 loop .stop ()
18871874
18881875 asyncio .set_event_loop (self .loop )
@@ -1909,8 +1896,7 @@ def stop_loop_coro(loop):
19091896class RunningLoopTests (unittest .TestCase ):
19101897
19111898 def test_running_loop_within_a_loop (self ):
1912- @asyncio .coroutine
1913- def runner (loop ):
1899+ async def runner (loop ):
19141900 loop .run_forever ()
19151901
19161902 loop = asyncio .new_event_loop ()
0 commit comments