mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-100112: avoid using iterable coroutines in asyncio internally (#100128)
This commit is contained in:
parent
1c9f3391b9
commit
a44553ea9f
3 changed files with 22 additions and 16 deletions
|
@ -8,6 +8,7 @@ import random
|
|||
import re
|
||||
import sys
|
||||
import traceback
|
||||
import types
|
||||
import unittest
|
||||
from unittest import mock
|
||||
from types import GenericAlias
|
||||
|
@ -274,6 +275,20 @@ class BaseTaskTests:
|
|||
loop.run_until_complete(fut)
|
||||
self.assertEqual(fut.result(), 'ok')
|
||||
|
||||
def test_ensure_future_task_awaitable(self):
|
||||
class Aw:
|
||||
def __await__(self):
|
||||
return asyncio.sleep(0, result='ok').__await__()
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
self.set_event_loop(loop)
|
||||
task = asyncio.ensure_future(Aw(), loop=loop)
|
||||
loop.run_until_complete(task)
|
||||
self.assertTrue(task.done())
|
||||
self.assertEqual(task.result(), 'ok')
|
||||
self.assertIsInstance(task.get_coro(), types.CoroutineType)
|
||||
loop.close()
|
||||
|
||||
def test_ensure_future_neither(self):
|
||||
with self.assertRaises(TypeError):
|
||||
asyncio.ensure_future('ok')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue