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:
Illia Volochii 2021-07-01 16:13:59 +03:00 committed by GitHub
parent 3623aaa78c
commit a1092f6249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 85 additions and 763 deletions

View file

@ -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())