@@ -41,19 +41,20 @@ def _get_event_loop(stacklevel=3):
4141        return  loop 
4242
4343    # Use module level _current_tasks, all_tasks and patch run method. 
44-     if  hasattr (asyncio , ' _nest_patched'  ):
44+     if  hasattr (asyncio , " _nest_patched"  ):
4545        return 
4646    if  sys .version_info  >=  (3 , 6 , 0 ):
47-         asyncio .Task  =  asyncio .tasks ._CTask  =  asyncio .tasks .Task  =  \
48-             asyncio .tasks ._PyTask 
49-         asyncio .Future  =  asyncio .futures ._CFuture  =  asyncio .futures .Future  =  \
47+         asyncio .Task  =  asyncio .tasks ._CTask  =  asyncio .tasks .Task  =  asyncio .tasks ._PyTask 
48+         asyncio .Future  =  asyncio .futures ._CFuture  =  asyncio .futures .Future  =  (
5049            asyncio .futures ._PyFuture 
50+         )
5151    if  sys .version_info  <  (3 , 7 , 0 ):
5252        asyncio .tasks ._current_tasks  =  asyncio .tasks .Task ._current_tasks 
5353        asyncio .all_tasks  =  asyncio .tasks .Task .all_tasks 
5454    if  sys .version_info  >=  (3 , 9 , 0 ):
55-         events ._get_event_loop  =  events .get_event_loop  =  \
56-             asyncio .get_event_loop  =  _get_event_loop 
55+         events ._get_event_loop  =  events .get_event_loop  =  asyncio .get_event_loop  =  (
56+             _get_event_loop 
57+         )
5758    asyncio .run  =  run 
5859    asyncio ._nest_patched  =  True 
5960
@@ -93,8 +94,7 @@ def run_until_complete(self, future):
9394                if  self ._stopping :
9495                    break 
9596            if  not  f .done ():
96-                 raise  RuntimeError (
97-                     'Event loop stopped before Future completed.' )
97+                 raise  RuntimeError ("Event loop stopped before Future completed." )
9898            return  f .result ()
9999
100100    def  _run_once (self ):
@@ -108,10 +108,12 @@ def _run_once(self):
108108            heappop (scheduled )
109109
110110        timeout  =  (
111-             0  if  ready  or  self ._stopping 
112-             else  min (max (
113-                 scheduled [0 ]._when  -  self .time (), 0 ), 86400 ) if  scheduled 
114-             else  None )
111+             0 
112+             if  ready  or  self ._stopping 
113+             else  min (max (scheduled [0 ]._when  -  self .time (), 0 ), 86400 )
114+             if  scheduled 
115+             else  None 
116+         )
115117        event_list  =  self ._selector .select (timeout )
116118        self ._process_events (event_list )
117119
@@ -157,8 +159,10 @@ def manage_run(self):
157159            events ._set_running_loop (old_running_loop )
158160            self ._num_runs_pending  -=  1 
159161            if  self ._is_proactorloop :
160-                 if  (self ._num_runs_pending  ==  0 
161-                         and  self ._self_reading_future  is  not   None ):
162+                 if  (
163+                     self ._num_runs_pending  ==  0 
164+                     and  self ._self_reading_future  is  not   None 
165+                 ):
162166                    ov  =  self ._self_reading_future ._ov 
163167                    self ._self_reading_future .cancel ()
164168                    if  ov  is  not   None :
@@ -167,7 +171,7 @@ def manage_run(self):
167171
168172    @contextmanager  
169173    def  manage_asyncgens (self ):
170-         if  not  hasattr (sys , ' get_asyncgen_hooks'  ):
174+         if  not  hasattr (sys , " get_asyncgen_hooks"  ):
171175            # Python version is too old. 
172176            return 
173177        old_agen_hooks  =  sys .get_asyncgen_hooks ()
@@ -176,7 +180,8 @@ def manage_asyncgens(self):
176180            if  self ._asyncgens  is  not   None :
177181                sys .set_asyncgen_hooks (
178182                    firstiter = self ._asyncgen_firstiter_hook ,
179-                     finalizer = self ._asyncgen_finalizer_hook )
183+                     finalizer = self ._asyncgen_finalizer_hook ,
184+                 )
180185            yield 
181186        finally :
182187            self ._set_coroutine_origin_tracking (False )
@@ -187,23 +192,27 @@ def _check_running(self):
187192        """Do not throw exception if loop is already running.""" 
188193        pass 
189194
190-     if  hasattr (loop , ' _nest_patched'  ):
195+     if  hasattr (loop , " _nest_patched"  ):
191196        return 
192197    if  not  isinstance (loop , asyncio .BaseEventLoop ):
193-         raise  ValueError (' Can\ ' t patch loop of type %s'   %  type (loop ))
198+         raise  ValueError (" Can't patch loop of type %s"   %  type (loop ))
194199    cls  =  loop .__class__ 
195200    cls .run_forever  =  run_forever 
196201    cls .run_until_complete  =  run_until_complete 
197202    cls ._run_once  =  _run_once 
198203    cls ._check_running  =  _check_running 
199204    cls ._check_runnung  =  _check_running   # typo in Python 3.7 source 
200205    cls ._num_runs_pending  =  1  if  loop .is_running () else  0 
201-     cls ._is_proactorloop  =  (
202-         os .name  ==  'nt'  and  issubclass (cls , asyncio .ProactorEventLoop ))
206+     cls ._is_proactorloop  =  os .name  ==  "nt"  and  issubclass (
207+         cls , asyncio .ProactorEventLoop 
208+     )
203209    if  sys .version_info  <  (3 , 7 , 0 ):
204210        cls ._set_coroutine_origin_tracking  =  cls ._set_coroutine_wrapper 
205-     curr_tasks  =  asyncio .tasks ._current_tasks  \
206-         if  sys .version_info  >=  (3 , 7 , 0 ) else  asyncio .Task ._current_tasks 
211+     curr_tasks  =  (
212+         asyncio .tasks ._current_tasks 
213+         if  sys .version_info  >=  (3 , 7 , 0 )
214+         else  asyncio .Task ._current_tasks 
215+     )
207216    cls ._nest_patched  =  True 
208217
209218
@@ -212,8 +221,9 @@ def _patch_tornado():
212221    If tornado is imported before nest_asyncio, make tornado aware of 
213222    the pure-Python asyncio Future. 
214223    """ 
215-     if  ' tornado'   in  sys .modules :
224+     if  " tornado"   in  sys .modules :
216225        import  tornado .concurrent  as  tc   # type: ignore 
226+ 
217227        tc .Future  =  asyncio .Future 
218228        if  asyncio .Future  not  in   tc .FUTURES :
219229            tc .FUTURES  +=  (asyncio .Future ,)
0 commit comments