8000 GH-94597: add deprecation warnings for subclassing `AbstractChildWatc… · python/cpython@aa87432 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa87432

Browse files
GH-94597: add deprecation warnings for subclassing AbstractChildWatcher (#99386)
1 parent e02cc6d commit aa87432

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

Doc/library/asyncio-policy.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ implementation used by the asyncio event loop:
222222
This method has to be called to ensure that underlying
223223
resources are cleaned-up.
224224

225+
.. deprecated:: 3.12
226+
227+
225228
.. class:: ThreadedChildWatcher
226229

227230
This implementation starts a new waiting thread for every subprocess spawn.

Doc/whatsnew/3.12.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ asyncio
203203
(Contributed by Kumar Aditya in :gh:`98024`.)
204204

205205
* The child watcher classes :class:`~asyncio.MultiLoopChildWatcher`,
206-
:class:`~asyncio.FastChildWatcher` and
207-
:class:`~asyncio.SafeChildWatcher` are deprecated and
206+
:class:`~asyncio.FastChildWatcher`, :class:`~asyncio.AbstractChildWatcher`
207+
and :class:`~asyncio.SafeChildWatcher` are deprecated and
208208
will be removed in Python 3.14. It is recommended to not manually
209209
configure a child watcher as the event loop now uses the best available
210210
child watcher for each platform (:class:`~asyncio.PidfdChildWatcher`

Lib/asyncio/unix_events.py

Lines changed: 7 additions & 0 deletions
< 8000 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,13 @@ class AbstractChildWatcher:
846846
waitpid(-1), there should be only one active object per process.
847847
"""
848848

849+
def __init_subclass__(cls) -> None:
850+
if cls.__module__ != __name__:
851+
warnings._deprecated("AbstractChildWatcher",
852+
"{name!r} is deprecated as of Python 3.12 and will be "
853+
"removed in Python {remove}.",
854+
remove=(3, 14))
855+
849856
def add_child_handler(self, pid, callback, *args):
850857
"""Register a new child handler.
851858

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,11 @@ def test_write_eof_pending(self):
11081108

11091109
class AbstractChildWatcherTests(unittest.TestCase):
11101110

1111+
def test_warns_on_subclassing(self):
1112+
with self.assertWarns(DeprecationWarning):
1113+
class MyWatcher(asyncio.AbstractChildWatcher):
1114+
pass
1115+
11111116
def test_not_implemented(self):
11121117
f = mock.Mock()
11131118
watcher = asyncio.AbstractChildWatcher()
@@ -1747,7 +1752,9 @@ def f():
17471752

17481753
self.assertIsInstance(policy.get_event_loop(),
17491754
asyncio.AbstractEventLoop)
1750-
watcher = policy.get_child_watcher()
1755+
with warnings.catch_warnings():
1756+
warnings.simplefilter("ignore", DeprecationWarning)
1757+
watcher = policy.get_child_watcher()
17511758

17521759
self.assertIsInstance(watcher, asyncio.SafeChildWatcher)
17531760
self.assertIsNone(watcher._loop)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate :class:`asyncio.AbstractChildWatcher` to be removed in Python 3.14. Patch by Kumar Aditya.

0 commit comments

Comments
 (0)
0