mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43216: Remove @asyncio.coroutine (GH-26369)
Remove the @asyncio.coroutine decorator enabling legacy generator-based coroutines to be compatible with async/await code; remove asyncio.coroutines.CoroWrapper used for wrapping legacy coroutine objects in the debug mode. The decorator has been deprecated since Python 3.8 and the removal was initially scheduled for Python 3.10.
This commit is contained in:
parent
3623aaa78c
commit
a1092f6249
11 changed files with 85 additions and 763 deletions
|
@ -38,14 +38,12 @@ class LockTests(test_utils.TestCase):
|
|||
def test_lock(self):
|
||||
lock = asyncio.Lock()
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
return (yield from lock)
|
||||
async def acquire_lock():
|
||||
return await lock
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
"object is not iterable"
|
||||
"object Lock can't be used in 'await' expression"
|
||||
):
|
||||
self.loop.run_until_complete(acquire_lock())
|
||||
|
||||
|
@ -78,18 +76,16 @@ class LockTests(test_utils.TestCase):
|
|||
asyncio.BoundedSemaphore(),
|
||||
]
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def test(lock):
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
"object is not iterable"
|
||||
):
|
||||
with (yield from lock):
|
||||
pass
|
||||
self.assertFalse(lock.locked())
|
||||
async def test(lock):
|
||||
await asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
r"object \w+ can't be used in 'await' expression"
|
||||
):
|
||||
with await lock:
|
||||
pass
|
||||
self.assertFalse(lock.locked())
|
||||
|
||||
for primitive in primitives:
|
||||
loop.run_until_complete(test(primitive))
|
||||
|
@ -788,14 +784,12 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
sem = asyncio.Semaphore()
|
||||
self.assertEqual(1, sem._value)
|
||||
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
return (yield from sem)
|
||||
async def acquire_lock():
|
||||
return await sem
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
"'Semaphore' object is not iterable",
|
||||
"object Semaphore can't be used in 'await' expression",
|
||||
):
|
||||
self.loop.run_until_complete(acquire_lock())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue