File tree 3 files changed +22
-1
lines changed
3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -768,7 +768,7 @@ def _done_callback(fut):
768
768
nonlocal nfinished
769
769
nfinished += 1
770
770
771
- if outer .done ():
771
+ if outer is None or outer .done ():
772
772
if not fut .cancelled ():
773
773
# Mark exception retrieved.
774
774
fut .exception ()
@@ -823,6 +823,7 @@ def _done_callback(fut):
823
823
children = []
824
824
nfuts = 0
825
825
nfinished = 0
826
+ outer = None # bpo-46672
826
827
for arg in coros_or_futures :
827
828
if arg not in arg_to_fut :
828
829
fut = ensure_future (arg , loop = loop )
Original file line number Diff line number Diff line change @@ -3407,6 +3407,11 @@ async def coro(fut=fut):
3407
3407
coros .append (coro ())
3408
3408
return coros
3409
3409
3410
+ def _gather (self , * args , ** kwargs ):
3411
+ async def coro ():
3412
+ return asyncio .gather (* args , ** kwargs )
3413
+ return self .one_loop .run_until_complete (coro ())
3414
+
3410
3415
def test_constructor_loop_selection (self ):
3411
3416
async def coro ():
3412
3417
return 'abc'
@@ -3488,6 +3493,20 @@ async def outer():
3488
3493
test_utils .run_briefly (self .one_loop )
3489
3494
self .assertIsInstance (f .exception (), RuntimeError )
3490
3495
3496
+ def test_issue46672 (self ):
3497
+ with mock .patch (
3498
+ 'asyncio.base_events.BaseEventLoop.call_exception_handler' ,
3499
+ ):
3500
+ async def coro (s ):
3501
+ return s
3502
+ c = coro ('abc' )
3503
+
3504
+ with self .assertRaises (TypeError ):
3505
+ self ._gather (c , {})
3506
+ self ._run_loop (self .one_loop )
3507
+ # NameError should not happen:
3508
+ self .one_loop .call_exception_handler .assert_not_called ()
3509
+
3491
3510
3492
3511
class RunCoroutineThreadsafeTests (test_utils .TestCase ):
3493
3512
"""Test case for asyncio.run_coroutine_threadsafe."""
Original file line number Diff line number Diff line change
1
+ Fix ``NameError `` in :func: `asyncio.gather ` when initial type check fails.
You can’t perform that action at this time.
0 commit comments