@@ -113,7 +113,11 @@ async def coro():
113113 self .assertTrue (hasattr (t , '_cancel_message' ))
114114 self .assertEqual (t ._cancel_message , None )
115115
116- t .cancel ('my message' )
116+ with self .assertWarnsRegex (
117+ DeprecationWarning ,
118+ "Passing 'msg' argument"
119+ ):
120+ t .cancel ('my message' )
117121 self .assertEqual (t ._cancel_message , 'my message' )
118122
119123 with self .assertRaises (asyncio .CancelledError ) as cm :
@@ -125,7 +129,11 @@ def test_task_cancel_message_setter(self):
125129 async def coro ():
126130 pass
127131 t = self .new_task (self .loop , coro ())
128- t .cancel ('my message' )
132+ with self .assertWarnsRegex (
133+ DeprecationWarning ,
134+ "Passing 'msg' argument"
135+ ):
136+ t .cancel ('my message' )
129137 t ._cancel_message = 'my new message'
130138 self .assertEqual (t ._cancel_message , 'my new message' )
131139
@@ -582,7 +590,14 @@ async def sleep():
582590 async def coro ():
583591 task = self .new_task (loop , sleep ())
584592 await asyncio .sleep (0 )
585- task .cancel (* cancel_args )
593+ if cancel_args not in ((), (None ,)):
594+ with self .assertWarnsRegex (
595+ DeprecationWarning ,
596+ "Passing 'msg' argument"
597+ ):
598+ task .cancel (* cancel_args )
599+ else :
600+ task .cancel (* cancel_args )
586601 done , pending = await asyncio .wait ([task ])
587602 task .result ()
588603
@@ -616,7 +631,14 @@ async def sleep():
616631 async def coro ():
617632 task = self .new_task (loop , sleep ())
618633 await asyncio .sleep (0 )
619- task .cancel (* cancel_args )
634+ if cancel_args not in ((), (None ,)):
635+ with self .assertWarnsRegex (
636+ DeprecationWarning ,
637+ "Passing 'msg' argument"
638+ ):
639+ task .cancel (* cancel_args )
640+ else :
641+ task .cancel (* cancel_args )
620642 done , pending = await asyncio .wait ([task ])
621643 task .exception ()
622644
@@ -639,10 +661,17 @@ async def sleep():
639661 fut .set_result (None )
640662 await asyncio .sleep (10 )
641663
664+ def cancel (task , msg ):
665+ with self .assertWarnsRegex (
666+ DeprecationWarning ,
667+ "Passing 'msg' argument"
668+ ):
669+ task .cancel (msg )
670+
642671 async def coro ():
643672 inner_task = self .new_task (loop , sleep ())
644673 await fut
645- loop .call_soon (inner_task . cancel , 'msg' )
674+ loop .call_soon (cancel , inner_task , 'msg' )
646675 try :
647676 await inner_task
648677 except asyncio .CancelledError as ex :
@@ -668,7 +697,11 @@ async def sleep():
668697 async def coro ():
669698 task = self .new_task (loop , sleep ())
670699 # We deliberately leave out the sleep here.
671- task .cancel ('my message' )
700+ with self .assertWarnsRegex (
701+ DeprecationWarning ,
702+ "Passing 'msg' argument"
703+ ):
704+ task .cancel ('my message' )
672705 done , pending = await asyncio .wait ([task ])
673706 task .exception ()
674707
@@ -2029,7 +2062,14 @@ async def test():
20292062 async def main ():
20302063 qwe = self .new_task (loop , test ())
20312064 await asyncio .sleep (0.2 )
2032- qwe .cancel (* cancel_args )
2065+ if cancel_args not in ((), (None ,)):
2066+ with self .assertWarnsRegex (
2067+ DeprecationWarning ,
2068+ "Passing 'msg' argument"
2069+ ):
2070+ qwe .cancel (* cancel_args )
2071+ else :
2072+ qwe .cancel (* cancel_args )
20332073 await qwe
20342074
20352075 try :
0 commit comments