Skip to content

Commit b2779b2

Browse files
Dreamsorcererambv
andauthored
[3.9] bpo-44815: Always show deprecation in asyncio.gather/sleep() (GH-27569)
Co-authored-by: Łukasz Langa <[email protected]>
1 parent ebe7e6d commit b2779b2

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

Lib/asyncio/tasks.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,17 @@ def __sleep0():
635635

636636
async def sleep(delay, result=None, *, loop=None):
637637
"""Coroutine that completes after a given time (in seconds)."""
638+
if loop is not None:
639+
warnings.warn("The loop argument is deprecated since Python 3.8, "
640+
"and scheduled for removal in Python 3.10.",
641+
DeprecationWarning, stacklevel=2)
642+
638643
if delay <= 0:
639644
await __sleep0()
640645
return result
641646

642647
if loop is None:
643648
loop = events.get_running_loop()
644-
else:
645-
warnings.warn("The loop argument is deprecated since Python 3.8, "
646-
"and scheduled for removal in Python 3.10.",
647-
DeprecationWarning, stacklevel=2)
648649

649650
future = loop.create_future()
650651
h = loop.call_later(delay,
@@ -750,13 +751,14 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
750751
after catching an exception (raised by one of the awaitables) from
751752
gather won't cancel any other awaitables.
752753
"""
754+
if loop is not None:
755+
warnings.warn("The loop argument is deprecated since Python 3.8, "
756+
"and scheduled for removal in Python 3.10.",
757+
DeprecationWarning, stacklevel=2)
758+
753759
if not coros_or_futures:
754760
if loop is None:
755761
loop = events.get_event_loop()
756-
else:
757-
warnings.warn("The loop argument is deprecated since Python 3.8, "
758-
"and scheduled for removal in Python 3.10.",
759-
DeprecationWarning, stacklevel=2)
760762
outer = loop.create_future()
761763
outer.set_result([])
762764
return outer

Lib/test/test_asyncio/__init__.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
import os
2-
from test.support import load_package_tests, import_module
2+
from test import support
3+
import unittest
34

45
# Skip tests if we don't have concurrent.futures.
5-
import_module('concurrent.futures')
6+
support.import_module('concurrent.futures')
67

7-
def load_tests(*args):
8-
return load_package_tests(os.path.dirname(__file__), *args)
8+
9+
def load_tests(loader, _, pattern):
10+
pkg_dir = os.path.dirname(__file__)
11+
suite = AsyncioTestSuite()
12+
return support.load_package_tests(pkg_dir, loader, suite, pattern)
13+
14+
15+
class AsyncioTestSuite(unittest.TestSuite):
16+
"""A custom test suite that also runs setup/teardown for the whole package.
17+
18+
Normally unittest only runs setUpModule() and tearDownModule() within each
19+
test module part of the test suite. Copying those functions to each file
20+
would be tedious, let's run this once and for all.
21+
"""
22+
def run(self, result, debug=False):
23+
ignore = support.ignore_deprecations_from
24+
tokens = {
25+
ignore("asyncio.base_events", like=r".*loop argument.*"),
26+
ignore("asyncio.unix_events", like=r".*loop argument.*"),
27+
ignore("asyncio.futures", like=r".*loop argument.*"),
28+
ignore("asyncio.runners", like=r".*loop argument.*"),
29+
ignore("asyncio.subprocess", like=r".*loop argument.*"),
30+
ignore("asyncio.tasks", like=r".*loop argument.*"),
31+
ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"),
32+
ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"),
33+
}
34+
try:
35+
super().run(result, debug=debug)
36+
finally:
37+
support.clear_ignored_deprecations(*tokens)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Always show ``loop=`` arg deprecations in :func:`asyncio.gather` and
2+
:func:`asyncio.sleep`

0 commit comments

Comments
 (0)