]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-100160: Remove any deprecation warnings in asyncio.get_event_loop() (#100412)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 10 Jan 2023 20:20:09 +0000 (22:20 +0200)
committerGitHub <noreply@github.com>
Tue, 10 Jan 2023 20:20:09 +0000 (12:20 -0800)
Some deprecation warnings will reappear (in a slightly different form) in 3.12.

Co-authored-by: Guido van Rossum <guido@python.org>
Doc/library/asyncio-eventloop.rst
Doc/library/asyncio-policy.rst
Doc/whatsnew/3.10.rst
Lib/asyncio/events.py
Lib/test/test_asyncio/test_events.py
Misc/NEWS.d/next/Library/2022-12-21-18-29-24.gh-issue-100160.isBmL5.rst [new file with mode: 0644]

index d32e848a84135ab978ec3abc931e8f7081803c76..c7343826be3f3049afc49f9d9a1f5de4014d55d9 100644 (file)
@@ -48,7 +48,7 @@ an event loop:
    running event loop.
 
    If there is no running event loop set, the function will return
-   the result of ``get_event_loop_policy().get_event_loop()`` call.
+   the result of the ``get_event_loop_policy().get_event_loop()`` call.
 
    Because this function has rather complex behavior (especially
    when custom event loop policies are in use), using the
@@ -59,15 +59,15 @@ 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
+      (and other functions which use it implicitly) emitted a
       :exc:`DeprecationWarning` if there was no running event loop, even if
-      the current loop was set.
+      the current loop was set on the policy.
+      In Python versions 3.10.9, 3.11.1 and 3.12 they emit a
+      :exc:`DeprecationWarning` if there is no running event loop and no
+      current loop is set.
+      In some future Python release this will become an error.
 
 .. function:: set_event_loop(loop)
 
index d0af45febd14e3f324e877797a1495d65b11743e..eb043b3e5e7f586f3e9a51e1fab5aab5b1c8f35a 100644 (file)
@@ -112,10 +112,11 @@ 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.
+   .. note::
+      In Python versions 3.10.9, 3.11.1 and 3.12 this function emits a
+      :exc:`DeprecationWarning` if there is no running event loop and no
+      current loop is set.
+      In some future Python release this will become an error.
 
 
 .. class:: WindowsSelectorEventLoopPolicy
index 33fdc6f0604c8b610398fcccdbb40db2d5ea2e38..ed72af717f6667f4180297a0f38cfb8057f7a815 100644 (file)
@@ -1708,19 +1708,6 @@ Deprecated
   scheduled for removal in Python 3.12.
   (Contributed by Erlend E. Aasland in :issue:`42264`.)
 
-* :func:`asyncio.get_event_loop` now emits a deprecation warning if there is
-  no running event loop. In the future it will be an alias of
-  :func:`~asyncio.get_running_loop`.
-  :mod:`asyncio` functions which implicitly create :class:`~asyncio.Future`
-  or :class:`~asyncio.Task` objects now emit
-  a deprecation warning if there is no running event loop and no explicit
-  *loop* argument is passed: :func:`~asyncio.ensure_future`,
-  :func:`~asyncio.wrap_future`, :func:`~asyncio.gather`,
-  :func:`~asyncio.shield`, :func:`~asyncio.as_completed` and constructors of
-  :class:`~asyncio.Future`, :class:`~asyncio.Task`,
-  :class:`~asyncio.StreamReader`, :class:`~asyncio.StreamReaderProtocol`.
-  (Contributed by Serhiy Storchaka in :issue:`39529`.)
-
 * The undocumented built-in function ``sqlite3.enable_shared_cache`` is now
   deprecated, scheduled for removal in Python 3.12.  Its use is strongly
   discouraged by the SQLite3 documentation.  See `the SQLite3 docs
index af3f9e970b5106da7549baf37ddaf77f189c6d19..b1799320eaa08dbfac833848fb1ee099d7e33dc0 100644 (file)
@@ -671,21 +671,6 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
         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:
index 3f92122b0c76679d5e736abf32f00d1d7b19e4d1..5728d25254f3690364c8836c266c55cfaadd4e39 100644 (file)
@@ -2588,9 +2588,7 @@ class PolicyTests(unittest.TestCase):
     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)
@@ -2604,10 +2602,8 @@ class PolicyTests(unittest.TestCase):
                 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
@@ -2796,10 +2792,8 @@ class GetEventLoopTestsMixin:
             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()
diff --git a/Misc/NEWS.d/next/Library/2022-12-21-18-29-24.gh-issue-100160.isBmL5.rst b/Misc/NEWS.d/next/Library/2022-12-21-18-29-24.gh-issue-100160.isBmL5.rst
new file mode 100644 (file)
index 0000000..c3b518c
--- /dev/null
@@ -0,0 +1,2 @@
+Remove any deprecation warnings in :func:`asyncio.get_event_loop`. They are
+deferred to Python 3.12.