From 19c9a03661a68be7a35e8b6d6ac353989c6962b3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 21 Dec 2022 18:29:52 +0200 Subject: [PATCH 1/5] gh-100160: Remove any deprecation warnings in asyncio.get_event_loop() They are deferred to Python 3.12. --- Doc/library/asyncio-eventloop.rst | 10 ---------- Doc/library/asyncio-policy.rst | 5 ----- Lib/asyncio/events.py | 15 --------------- Lib/test/test_asyncio/test_events.py | 12 +++--------- ...2022-12-21-18-29-24.gh-issue-100160.isBmL5.rst | 2 ++ 5 files changed, 5 insertions(+), 39 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-12-21-18-29-24.gh-issue-100160.isBmL5.rst diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index d32e848a84135a..e758a2b24d1f02 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -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. diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst index d0af45febd14e3..bfc3e3090fdcdf 100644 --- a/Doc/library/asyncio-policy.rst +++ b/Doc/library/asyncio-policy.rst @@ -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 diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index af3f9e970b5106..b1799320eaa08d 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -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: diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index c431fea401633e..18c4fd15d9aff4 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -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) @@ -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 @@ -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() 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 index 00000000000000..c3b518ca85d790 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-12-21-18-29-24.gh-issue-100160.isBmL5.rst @@ -0,0 +1,2 @@ +Remove any deprecation warnings in :func:`asyncio.get_event_loop`. They are +deferred to Python 3.12. From e930e8a2ae7ab6ae1476aca70c0f9bb8fbadb1fd Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 22 Dec 2022 09:34:55 +0200 Subject: [PATCH 2/5] Apply suggestions from the code review. --- Doc/library/asyncio-eventloop.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index e758a2b24d1f02..a86db6cec2335f 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -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 From e2a58b61bb825ac6bb8bf2f19ed134c4be0dbce4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 22 Dec 2022 10:02:25 +0200 Subject: [PATCH 3/5] Update docs. --- Doc/library/asyncio-eventloop.rst | 10 ++++++++++ Doc/library/asyncio-policy.rst | 6 ++++++ Doc/whatsnew/3.10.rst | 13 ------------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index a86db6cec2335f..43dad88ce1316d 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -59,6 +59,16 @@ an event loop: instead of using these lower level functions to manually create and close an event loop. + .. 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. + In Python versions 3.10.9, 3.11.1, and 3.12 they emitted a + :exc:`DeprecationWarning` if there was no running event loop, and no + current loop was set. + In some future Python release it will become an error. + .. function:: set_event_loop(loop) Set *loop* as the current event loop for the current OS thread. diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst index bfc3e3090fdcdf..b59ce6a1763654 100644 --- a/Doc/library/asyncio-policy.rst +++ b/Doc/library/asyncio-policy.rst @@ -112,6 +112,12 @@ asyncio ships with the following built-in policies: On Windows, :class:`ProactorEventLoop` is now used by default. + .. note:: + In Python versions 3.10.9, 3.11.1, and 3.12 this function emitted a + :exc:`DeprecationWarning` if there was no running event loop, and no + current loop was set. + In some future Python release it will become an error. + .. class:: WindowsSelectorEventLoopPolicy diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index d0b436664ac33f..38b30deff719b9 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1710,19 +1710,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 From 5921a13f845468755832ab456b789b88b2cf476d Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 10 Jan 2023 10:57:43 -0800 Subject: [PATCH 4/5] Improve the doc notes a bit --- Doc/library/asyncio-eventloop.rst | 10 +++++----- Doc/library/asyncio-policy.rst | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 43dad88ce1316d..3c9c12877fac4e 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -61,13 +61,13 @@ an event loop: .. 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. - In Python versions 3.10.9, 3.11.1, and 3.12 they emitted a - :exc:`DeprecationWarning` if there was no running event loop, and no + 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 was no running event loop and no current loop was set. - In some future Python release it will become an error. + In some future Python release this will become an error. .. function:: set_event_loop(loop) diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst index b59ce6a1763654..901c5969fd2b66 100644 --- a/Doc/library/asyncio-policy.rst +++ b/Doc/library/asyncio-policy.rst @@ -113,10 +113,10 @@ asyncio ships with the following built-in policies: On Windows, :class:`ProactorEventLoop` is now used by default. .. note:: - In Python versions 3.10.9, 3.11.1, and 3.12 this function emitted a - :exc:`DeprecationWarning` if there was no running event loop, and no + 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 was set. - In some future Python release it will become an error. + In some future Python release this will become an error. .. class:: WindowsSelectorEventLoopPolicy From e57283fe2148a465c4252c2db9401c1360ed4dd5 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 10 Jan 2023 11:45:16 -0800 Subject: [PATCH 5/5] More tense tweaks --- Doc/library/asyncio-eventloop.rst | 4 ++-- Doc/library/asyncio-policy.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 3c9c12877fac4e..c7343826be3f30 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -65,8 +65,8 @@ an event loop: :exc:`DeprecationWarning` if there was no running event loop, even if 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 was no running event loop and no - current loop was set. + :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) diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst index 901c5969fd2b66..eb043b3e5e7f58 100644 --- a/Doc/library/asyncio-policy.rst +++ b/Doc/library/asyncio-policy.rst @@ -115,7 +115,7 @@ asyncio ships with the following built-in policies: .. 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 was set. + current loop is set. In some future Python release this will become an error.