[3.9] bpo-45097: Remove incorrect deprecation warnings in asyncio. (GH-28153)

Deprecation warnings about the loop argument were incorrectly emitted
in cases when the loop argument was used inside the asyncio library,
not from user code.
This commit is contained in:
Serhiy Storchaka 2021-09-04 20:54:50 +03:00 committed by GitHub
parent ce83e42437
commit c967bd523c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 234 additions and 181 deletions

View file

@ -1606,8 +1606,9 @@ class BaseTaskTests:
for f in asyncio.as_completed([b, c, a], loop=loop):
values.append(await f)
return values
with self.assertWarns(DeprecationWarning):
with self.assertWarns(DeprecationWarning) as w:
res = loop.run_until_complete(self.new_task(loop, foo()))
self.assertEqual(w.warnings[0].filename, __file__)
self.assertAlmostEqual(0.15, loop.time())
self.assertTrue('a' in res[:2])
self.assertTrue('b' in res[:2])
@ -3348,7 +3349,8 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
with self.assertRaises(ValueError):
asyncio.gather(fut1, fut2)
with self.assertRaises(ValueError):
asyncio.gather(fut1, loop=self.other_loop)
with self.assertWarns(DeprecationWarning):
asyncio.gather(fut1, loop=self.other_loop)
def test_constructor_homogenous_futures(self):
children = [self.other_loop.create_future() for i in range(3)]
@ -3356,7 +3358,8 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
self.assertIs(fut._loop, self.other_loop)
self._run_loop(self.other_loop)
self.assertFalse(fut.done())
fut = asyncio.gather(*children, loop=self.other_loop)
with self.assertWarns(DeprecationWarning):
fut = asyncio.gather(*children, loop=self.other_loop)
self.assertIs(fut._loop, self.other_loop)
self._run_loop(self.other_loop)
self.assertFalse(fut.done())
@ -3429,7 +3432,8 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
self.set_event_loop(self.other_loop, cleanup=False)
gen3 = coro()
gen4 = coro()
fut2 = asyncio.gather(gen3, gen4, loop=self.other_loop)
with self.assertWarns(DeprecationWarning):
fut2 = asyncio.gather(gen3, gen4, loop=self.other_loop)
self.assertIs(fut2._loop, self.other_loop)
self.other_loop.run_until_complete(fut2)
@ -3439,7 +3443,8 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
def coro(s):
return s
c = coro('abc')
fut = asyncio.gather(c, c, coro('def'), c, loop=self.one_loop)
with self.assertWarns(DeprecationWarning):
fut = asyncio.gather(c, c, coro('def'), c, loop=self.one_loop)
self._run_loop(self.one_loop)
self.assertEqual(fut.result(), ['abc', 'abc', 'def', 'abc'])
@ -3459,7 +3464,7 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
async def outer():
nonlocal proof, gatherer
gatherer = asyncio.gather(child1, child2, loop=self.one_loop)
gatherer = asyncio.gather(child1, child2)
await gatherer
proof += 100
@ -3486,7 +3491,7 @@ class CoroutineGatherTests(GatherTestsBase, test_utils.TestCase):
b = self.one_loop.create_future()
async def outer():
await asyncio.gather(inner(a), inner(b), loop=self.one_loop)
await asyncio.gather(inner(a), inner(b))
f = asyncio.ensure_future(outer(), loop=self.one_loop)
test_utils.run_briefly(self.one_loop)
@ -3705,7 +3710,7 @@ class CompatibilityTests(test_utils.TestCase):
return 'ok2'
async def inner():
return await asyncio.gather(coro1(), coro2(), loop=self.loop)
return await asyncio.gather(coro1(), coro2())
result = self.loop.run_until_complete(inner())
self.assertEqual(['ok1', 'ok2'], result)