Skip to content

Commit 1b2459d

Browse files
[3.11] gh-100160: Remove any deprecation warnings in asyncio.get_event_loop() (#100412)
Some deprecation warnings will reappear (in a slightly different form) in 3.12. Co-authored-by: Guido van Rossum <guido@python.org>
1 parent a7f9afd commit 1b2459d

File tree

6 files changed

+17
-48
lines changed

6 files changed

+17
-48
lines changed

Doc/library/asyncio-eventloop.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ an event loop:
4848
running event loop.
4949

5050
If there is no running event loop set, the function will return
51-
the result of ``get_event_loop_policy().get_event_loop()`` call.
51+
the result of the ``get_event_loop_policy().get_event_loop()`` call.
5252

5353
Because this function has rather complex behavior (especially
5454
when custom event loop policies are in use), using the
@@ -59,15 +59,15 @@ an event loop:
5959
instead of using these lower level functions to manually create and close an
6060
event loop.
6161

62-
.. deprecated:: 3.10
63-
Deprecation warning is emitted if there is no current event loop.
64-
In Python 3.12 it will be an error.
65-
6662
.. note::
6763
In Python versions 3.10.0--3.10.8 and 3.11.0 this function
68-
(and other functions which used it implicitly) emitted a
64+
(and other functions which use it implicitly) emitted a
6965
:exc:`DeprecationWarning` if there was no running event loop, even if
70-
the current loop was set.
66+
the current loop was set on the policy.
67+
In Python versions 3.10.9, 3.11.1 and 3.12 they emit a
68+
:exc:`DeprecationWarning` if there is no running event loop and no
69+
current loop is set.
70+
In some future Python release this will become an error.
7171

7272
.. function:: set_event_loop(loop)
7373

Doc/library/asyncio-policy.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ asyncio ships with the following built-in policies:
112112

113113
On Windows, :class:`ProactorEventLoop` is now used by default.
114114

115-
.. deprecated:: 3.11.1
116-
:meth:`get_event_loop` now emits a :exc:`DeprecationWarning` if there
117-
is no current event loop set and a new event loop has been implicitly
118-
created. In Python 3.12 it will be an error.
115+
.. note::
116+
In Python versions 3.10.9, 3.11.1 and 3.12 this function emits a
117+
:exc:`DeprecationWarning` if there is no running event loop and no
118+
current loop is set.
119+
In some future Python release this will become an error.
119120

120121

121122
.. class:: WindowsSelectorEventLoopPolicy

Doc/whatsnew/3.10.rst

-13
Original file line numberDiff line numberDiff line change
@@ -1708,19 +1708,6 @@ Deprecated
17081708
scheduled for removal in Python 3.12.
17091709
(Contributed by Erlend E. Aasland in :issue:`42264`.)
17101710
1711-
* :func:`asyncio.get_event_loop` now emits a deprecation warning if there is
1712-
no running event loop. In the future it will be an alias of
1713-
:func:`~asyncio.get_running_loop`.
1714-
:mod:`asyncio` functions which implicitly create :class:`~asyncio.Future`
1715-
or :class:`~asyncio.Task` objects now emit
1716-
a deprecation warning if there is no running event loop and no explicit
1717-
*loop* argument is passed: :func:`~asyncio.ensure_future`,
1718-
:func:`~asyncio.wrap_future`, :func:`~asyncio.gather`,
1719-
:func:`~asyncio.shield`, :func:`~asyncio.as_completed` and constructors of
1720-
:class:`~asyncio.Future`, :class:`~asyncio.Task`,
1721-
:class:`~asyncio.StreamReader`, :class:`~asyncio.StreamReaderProtocol`.
1722-
(Contributed by Serhiy Storchaka in :issue:`39529`.)
1723-
17241711
* The undocumented built-in function ``sqlite3.enable_shared_cache`` is now
17251712
deprecated, scheduled for removal in Python 3.12. Its use is strongly
17261713
discouraged by the SQLite3 documentation. See `the SQLite3 docs

Lib/asyncio/events.py

-15
Original file line numberDiff line numberDiff line change
@@ -671,21 +671,6 @@ def get_event_loop(self):
671671
if (self._local._loop is None and
672672
not self._local._set_called and
673673
threading.current_thread() is threading.main_thread()):
674-
stacklevel = 2
675-
try:
676-
f = sys._getframe(1)
677-
except AttributeError:
678-
pass
679-
else:
680-
while f:
681-
module = f.f_globals.get('__name__')
682-
if not (module == 'asyncio' or module.startswith('asyncio.')):
683-
break
684-
f = f.f_back
685-
stacklevel += 1
686-
import warnings
687-
warnings.warn('There is no current event loop',
688-
DeprecationWarning, stacklevel=stacklevel)
689674
self.set_event_loop(self.new_event_loop())
690675

691676
if self._local._loop is None:

Lib/test/test_asyncio/test_events.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -2588,9 +2588,7 @@ def test_event_loop_policy(self):
25882588
def test_get_event_loop(self):
25892589
policy = asyncio.DefaultEventLoopPolicy()
25902590
self.assertIsNone(policy._local._loop)
2591-
with self.assertWarns(DeprecationWarning) as cm:
2592-
loop = policy.get_event_loop()
2593-
self.assertEqual(cm.filename, __file__)
2591+
loop = policy.get_event_loop()
25942592
self.assertIsInstance(loop, asyncio.AbstractEventLoop)
25952593

25962594
self.assertIs(policy._local._loop, loop)
@@ -2604,10 +2602,8 @@ def test_get_event_loop_calls_set_event_loop(self):
26042602
policy, "set_event_loop",
26052603
wraps=policy.set_event_loop) as m_set_event_loop:
26062604

2607-
with self.assertWarns(DeprecationWarning) as cm:
2608-
loop = policy.get_event_loop()
2605+
loop = policy.get_event_loop()
26092606
self.addCleanup(loop.close)
2610-
self.assertEqual(cm.filename, __file__)
26112607

26122608
# policy._local._loop must be set through .set_event_loop()
26132609
# (the unix DefaultEventLoopPolicy needs this call to attach
@@ -2796,10 +2792,8 @@ def test_get_event_loop_returns_running_loop2(self):
27962792
loop = asyncio.new_event_loop()
27972793
self.addCleanup(loop.close)
27982794

2799-
with self.assertWarns(DeprecationWarning) as cm:
2800-
loop2 = asyncio.get_event_loop()
2795+
loop2 = asyncio.get_event_loop()
28012796
self.addCleanup(loop2.close)
2802-
self.assertEqual(cm.filename, __file__)
28032797
asyncio.set_event_loop(None)
28042798
with self.assertRaisesRegex(RuntimeError, 'no current'):
28052799
asyncio.get_event_loop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove any deprecation warnings in :func:`asyncio.get_event_loop`. They are
2+
deferred to Python 3.12.

0 commit comments

Comments
 (0)