[Python-checkins] GH-94597: add deprecation warnings for subclassing `AbstractChildWatcher` (#99386)
gvanrossum
webhook-mailer at python.org
Sat Nov 12 02:17:58 EST 2022
https://github.com/python/cpython/commit/aa874326d86734606a1930e7f48e2ee204cae0b6
commit: aa874326d86734606a1930e7f48e2ee204cae0b6
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-11-11T23:17:53-08:00
summary:
GH-94597: add deprecation warnings for subclassing `AbstractChildWatcher` (#99386)
files:
A Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst
M Doc/library/asyncio-policy.rst
M Doc/whatsnew/3.12.rst
M Lib/asyncio/unix_events.py
M Lib/test/test_asyncio/test_unix_events.py
diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst
index 052378ef3274..98c850158746 100644
--- a/Doc/library/asyncio-policy.rst
+++ b/Doc/library/asyncio-policy.rst
@@ -222,6 +222,9 @@ implementation used by the asyncio event loop:
This method has to be called to ensure that underlying
resources are cleaned-up.
+ .. deprecated:: 3.12
+
+
.. class:: ThreadedChildWatcher
This implementation starts a new waiting thread for every subprocess spawn.
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index 37b9fb1ea4e8..ead2a9e718a9 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -203,8 +203,8 @@ asyncio
(Contributed by Kumar Aditya in :gh:`98024`.)
* The child watcher classes :class:`~asyncio.MultiLoopChildWatcher`,
- :class:`~asyncio.FastChildWatcher` and
- :class:`~asyncio.SafeChildWatcher` are deprecated and
+ :class:`~asyncio.FastChildWatcher`, :class:`~asyncio.AbstractChildWatcher`
+ and :class:`~asyncio.SafeChildWatcher` are deprecated and
will be removed in Python 3.14. It is recommended to not manually
configure a child watcher as the event loop now uses the best available
child watcher for each platform (:class:`~asyncio.PidfdChildWatcher`
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 2de7a1bfd681..b21e0394141b 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -846,6 +846,13 @@ class AbstractChildWatcher:
waitpid(-1), there should be only one active object per process.
"""
+ def __init_subclass__(cls) -> None:
+ if cls.__module__ != __name__:
+ warnings._deprecated("AbstractChildWatcher",
+ "{name!r} is deprecated as of Python 3.12 and will be "
+ "removed in Python {remove}.",
+ remove=(3, 14))
+
def add_child_handler(self, pid, callback, *args):
"""Register a new child handler.
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index d806ed497aaa..93e8611f184d 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -1108,6 +1108,11 @@ def test_write_eof_pending(self):
class AbstractChildWatcherTests(unittest.TestCase):
+ def test_warns_on_subclassing(self):
+ with self.assertWarns(DeprecationWarning):
+ class MyWatcher(asyncio.AbstractChildWatcher):
+ pass
+
def test_not_implemented(self):
f = mock.Mock()
watcher = asyncio.AbstractChildWatcher()
@@ -1747,7 +1752,9 @@ def f():
self.assertIsInstance(policy.get_event_loop(),
asyncio.AbstractEventLoop)
- watcher = policy.get_child_watcher()
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.SafeChildWatcher)
self.assertIsNone(watcher._loop)
diff --git a/Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst b/Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst
new file mode 100644
index 000000000000..5e649a88fdde
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst
@@ -0,0 +1 @@
+Deprecate :class:`asyncio.AbstractChildWatcher` to be removed in Python 3.14. Patch by Kumar Aditya.
More information about the Python-checkins
mailing list