mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-32253: Deprecate with statement and bare await for asyncio locks (GH-4764)
* Add test for 'with (yield from lock)' * Deprecate with statement for asyncio locks * Document the deprecation
This commit is contained in:
parent
a9f8df646a
commit
28d8d14013
5 changed files with 108 additions and 55 deletions
|
@ -59,12 +59,13 @@ class LockTests(BaseTest):
|
|||
async def test(lock):
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
self.assertFalse(lock.locked())
|
||||
with await lock as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
self.assertTrue(lock.locked())
|
||||
self.assertFalse(lock.locked())
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with await lock as _lock:
|
||||
self.assertIs(_lock, None)
|
||||
self.assertTrue(lock.locked())
|
||||
await asyncio.sleep(0.01, loop=self.loop)
|
||||
self.assertTrue(lock.locked())
|
||||
self.assertFalse(lock.locked())
|
||||
|
||||
for primitive in primitives:
|
||||
self.loop.run_until_complete(test(primitive))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue