GH-94597: add deprecation warnings for subclassing AbstractChildWatcher (#99386)

This commit is contained in:
Kumar Aditya 2022-11-12 12:47:53 +05:30 committed by GitHub
parent e02cc6d42a
commit aa874326d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 3 deletions

View file

@ -222,6 +222,9 @@ implementation used by the asyncio event loop:
This method has to be called to ensure that underlying This method has to be called to ensure that underlying
resources are cleaned-up. resources are cleaned-up.
.. deprecated:: 3.12
.. class:: ThreadedChildWatcher .. class:: ThreadedChildWatcher
This implementation starts a new waiting thread for every subprocess spawn. This implementation starts a new waiting thread for every subprocess spawn.

View file

@ -203,8 +203,8 @@ asyncio
(Contributed by Kumar Aditya in :gh:`98024`.) (Contributed by Kumar Aditya in :gh:`98024`.)
* The child watcher classes :class:`~asyncio.MultiLoopChildWatcher`, * The child watcher classes :class:`~asyncio.MultiLoopChildWatcher`,
:class:`~asyncio.FastChildWatcher` and :class:`~asyncio.FastChildWatcher`, :class:`~asyncio.AbstractChildWatcher`
:class:`~asyncio.SafeChildWatcher` are deprecated and and :class:`~asyncio.SafeChildWatcher` are deprecated and
will be removed in Python 3.14. It is recommended to not manually 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 configure a child watcher as the event loop now uses the best available
child watcher for each platform (:class:`~asyncio.PidfdChildWatcher` child watcher for each platform (:class:`~asyncio.PidfdChildWatcher`

View file

@ -846,6 +846,13 @@ class AbstractChildWatcher:
waitpid(-1), there should be only one active object per process. 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): def add_child_handler(self, pid, callback, *args):
"""Register a new child handler. """Register a new child handler.

View file

@ -1108,6 +1108,11 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
class AbstractChildWatcherTests(unittest.TestCase): class AbstractChildWatcherTests(unittest.TestCase):
def test_warns_on_subclassing(self):
with self.assertWarns(DeprecationWarning):
class MyWatcher(asyncio.AbstractChildWatcher):
pass
def test_not_implemented(self): def test_not_implemented(self):
f = mock.Mock() f = mock.Mock()
watcher = asyncio.AbstractChildWatcher() watcher = asyncio.AbstractChildWatcher()
@ -1747,6 +1752,8 @@ class PolicyTests(unittest.TestCase):
self.assertIsInstance(policy.get_event_loop(), self.assertIsInstance(policy.get_event_loop(),
asyncio.AbstractEventLoop) asyncio.AbstractEventLoop)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
watcher = policy.get_child_watcher() watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.SafeChildWatcher) self.assertIsInstance(watcher, asyncio.SafeChildWatcher)

View file

@ -0,0 +1 @@
Deprecate :class:`asyncio.AbstractChildWatcher` to be removed in Python 3.14. Patch by Kumar Aditya.