mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-36921: Deprecate @coroutine for sake of async def (GH-13346)
The second attempt. Now deprecate `@coroutine` only, keep `yield from fut` as is. https://bugs.python.org/issue36921
This commit is contained in:
parent
dbacfc2273
commit
68b34a7204
12 changed files with 311 additions and 320 deletions
|
@ -44,10 +44,11 @@ class LockTests(test_utils.TestCase):
|
|||
self.assertTrue(repr(lock).endswith('[unlocked]>'))
|
||||
self.assertTrue(RGX_REPR.match(repr(lock)))
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
yield from lock
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
yield from lock
|
||||
|
||||
self.loop.run_until_complete(acquire_lock())
|
||||
self.assertTrue(repr(lock).endswith('[locked]>'))
|
||||
|
@ -56,10 +57,11 @@ class LockTests(test_utils.TestCase):
|
|||
def test_lock(self):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from lock)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from lock)
|
||||
|
||||
res = self.loop.run_until_complete(acquire_lock())
|
||||
|
||||
|
@ -79,17 +81,18 @@ class LockTests(test_utils.TestCase):
|
|||
asyncio.BoundedSemaphore(loop=loop),
|
||||
]
|
||||
|
||||
@asyncio.coroutine
|
||||
def test(lock):
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with (yield from lock) as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertTrue(lock.locked())
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def test(lock):
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with (yield from lock) as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
yield from asyncio.sleep(0.01)
|
||||
self.assertTrue(lock.locked())
|
||||
self.assertFalse(lock.locked())
|
||||
|
||||
for primitive in primitives:
|
||||
loop.run_until_complete(test(primitive))
|
||||
|
@ -290,10 +293,11 @@ class LockTests(test_utils.TestCase):
|
|||
def test_context_manager(self):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from lock)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from lock)
|
||||
|
||||
with self.loop.run_until_complete(acquire_lock()):
|
||||
self.assertTrue(lock.locked())
|
||||
|
@ -303,10 +307,11 @@ class LockTests(test_utils.TestCase):
|
|||
def test_context_manager_cant_reuse(self):
|
||||
lock = asyncio.Lock(loop=self.loop)
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from lock)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from lock)
|
||||
|
||||
# This spells "yield from lock" outside a generator.
|
||||
cm = self.loop.run_until_complete(acquire_lock())
|
||||
|
@ -773,10 +778,11 @@ class ConditionTests(test_utils.TestCase):
|
|||
def test_context_manager(self):
|
||||
cond = asyncio.Condition(loop=self.loop)
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_cond():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from cond)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_cond():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from cond)
|
||||
|
||||
with self.loop.run_until_complete(acquire_cond()):
|
||||
self.assertTrue(cond.locked())
|
||||
|
@ -869,10 +875,11 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
sem = asyncio.Semaphore(loop=self.loop)
|
||||
self.assertEqual(1, sem._value)
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from sem)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from sem)
|
||||
|
||||
res = self.loop.run_until_complete(acquire_lock())
|
||||
|
||||
|
@ -1012,10 +1019,11 @@ class SemaphoreTests(test_utils.TestCase):
|
|||
def test_context_manager(self):
|
||||
sem = asyncio.Semaphore(2, loop=self.loop)
|
||||
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from sem)
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
@asyncio.coroutine
|
||||
def acquire_lock():
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
return (yield from sem)
|
||||
|
||||
with self.loop.run_until_complete(acquire_lock()):
|
||||
self.assertFalse(sem.locked())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue