Skip to content

Commit

Permalink
pythongh-100160: Remove any deprecation warnings in asyncio.get_event…
Browse files Browse the repository at this point in the history
…_loop()

They are deferred to Python 3.12.
  • Loading branch information
serhiy-storchaka committed Dec 21, 2022
1 parent 0397f04 commit 19c9a03
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 39 deletions.
10 changes: 0 additions & 10 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ an event loop:
instead of using these lower level functions to manually create and close an
event loop.

.. deprecated:: 3.10
Deprecation warning is emitted if there is no current event loop.
In Python 3.12 it will be an error.

.. note::
In Python versions 3.10.0--3.10.8 and 3.11.0 this function
(and other functions which used it implicitly) emitted a
:exc:`DeprecationWarning` if there was no running event loop, even if
the current loop was set.

.. function:: set_event_loop(loop)

Set *loop* as the current event loop for the current OS thread.
Expand Down
5 changes: 0 additions & 5 deletions Doc/library/asyncio-policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ asyncio ships with the following built-in policies:

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

.. deprecated:: 3.11.1
:meth:`get_event_loop` now emits a :exc:`DeprecationWarning` if there
is no current event loop set and a new event loop has been implicitly
created. In Python 3.12 it will be an error.


.. class:: WindowsSelectorEventLoopPolicy

Expand Down
15 changes: 0 additions & 15 deletions Lib/asyncio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,21 +671,6 @@ def get_event_loop(self):
if (self._local._loop is None and
not self._local._set_called and
threading.current_thread() is threading.main_thread()):
stacklevel = 2
try:
f = sys._getframe(1)
except AttributeError:
pass
else:
while f:
module = f.f_globals.get('__name__')
if not (module == 'asyncio' or module.startswith('asyncio.')):
break
f = f.f_back
stacklevel += 1
import warnings
warnings.warn('There is no current event loop',
DeprecationWarning, stacklevel=stacklevel)
self.set_event_loop(self.new_event_loop())

if self._local._loop is None:
Expand Down
12 changes: 3 additions & 9 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,9 +2547,7 @@ def test_event_loop_policy(self):
def test_get_event_loop(self):
policy = asyncio.DefaultEventLoopPolicy()
self.assertIsNone(policy._local._loop)
with self.assertWarns(DeprecationWarning) as cm:
loop = policy.get_event_loop()
self.assertEqual(cm.filename, __file__)
loop = policy.get_event_loop()
self.assertIsInstance(loop, asyncio.AbstractEventLoop)

self.assertIs(policy._local._loop, loop)
Expand All @@ -2563,10 +2561,8 @@ def test_get_event_loop_calls_set_event_loop(self):
policy, "set_event_loop",
wraps=policy.set_event_loop) as m_set_event_loop:

with self.assertWarns(DeprecationWarning) as cm:
loop = policy.get_event_loop()
loop = policy.get_event_loop()
self.addCleanup(loop.close)
self.assertEqual(cm.filename, __file__)

# policy._local._loop must be set through .set_event_loop()
# (the unix DefaultEventLoopPolicy needs this call to attach
Expand Down Expand Up @@ -2755,10 +2751,8 @@ def test_get_event_loop_returns_running_loop2(self):
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)

with self.assertWarns(DeprecationWarning) as cm:
loop2 = asyncio.get_event_loop()
loop2 = asyncio.get_event_loop()
self.addCleanup(loop2.close)
self.assertEqual(cm.filename, __file__)
asyncio.set_event_loop(None)
with self.assertRaisesRegex(RuntimeError, 'no current'):
asyncio.get_event_loop()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove any deprecation warnings in :func:`asyncio.get_event_loop`. They are
deferred to Python 3.12.

0 comments on commit 19c9a03

Please sign in to comment.