Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def _done_callback(fut):
nonlocal nfinished
nfinished += 1

if outer.done():
if outer is None or outer.done():
if not fut.cancelled():
# Mark exception retrieved.
fut.exception()
Expand Down Expand Up @@ -777,6 +777,7 @@ def _done_callback(fut):
nfuts = 0
nfinished = 0
loop = None
outer = None # bpo-46672
for arg in coros_or_futures:
if arg not in arg_to_fut:
fut = _ensure_future(arg, loop=loop)
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3593,6 +3593,20 @@ async def outer():
test_utils.run_briefly(self.one_loop)
self.assertIsInstance(f.exception(), RuntimeError)

def test_issue46672(self):
with mock.patch(
'asyncio.base_events.BaseEventLoop.call_exception_handler',
):
async def coro(s):
return s
c = coro('abc')

with self.assertRaises(TypeError):
self._gather(c, {})
self._run_loop(self.one_loop)
# NameError should not happen:
self.one_loop.call_exception_handler.assert_not_called()


class RunCoroutineThreadsafeTests(test_utils.TestCase):
"""Test case for asyncio.run_coroutine_threadsafe."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``NameError`` in :func:`asyncio.gather` when initial type check fails.