Skip to content

Commit fd750bf

Browse files
authored
asyncio.unix_events: Make AbstractChildWatcher abstract, add PidfdChildWatcher (#7412)
1 parent 7f2cf52 commit fd750bf

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

stdlib/asyncio/unix_events.pyi

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import sys
22
import types
33
from _typeshed import Self
4+
from abc import ABCMeta, abstractmethod
45
from socket import socket
56
from typing import Any, Callable
7+
from typing_extensions import Literal
68

79
from .base_events import Server
810
from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy, _ProtocolFactory, _SSLContext
@@ -12,13 +14,20 @@ from .selector_events import BaseSelectorEventLoop
1214
# but other parts of typeshed need this defintion.
1315
# So, it is special cased.
1416
class AbstractChildWatcher:
17+
@abstractmethod
1518
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
19+
@abstractmethod
1620
def remove_child_handler(self, pid: int) -> bool: ...
21+
@abstractmethod
1722
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
23+
@abstractmethod
1824
def close(self) -> None: ...
25+
@abstractmethod
1926
def __enter__(self: Self) -> Self: ...
27+
@abstractmethod
2028
def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ...
2129
if sys.version_info >= (3, 8):
30+
@abstractmethod
2231
def is_active(self) -> bool: ...
2332

2433
if sys.platform != "win32":
@@ -48,14 +57,27 @@ if sys.platform != "win32":
4857
else:
4958
__all__ = ["SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy"]
5059

51-
class BaseChildWatcher(AbstractChildWatcher):
60+
# Doesn't actually have ABCMeta metaclass at runtime, but mypy complains if we don't have it in the stub.
61+
# See discussion in #7412
62+
class BaseChildWatcher(AbstractChildWatcher, metaclass=ABCMeta):
5263
def __init__(self) -> None: ...
64+
def close(self) -> None: ...
65+
if sys.version_info >= (3, 8):
66+
def is_active(self) -> bool: ...
67+
68+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
5369

5470
class SafeChildWatcher(BaseChildWatcher):
5571
def __enter__(self: Self) -> Self: ...
72+
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
73+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
74+
def remove_child_handler(self, pid: int) -> bool: ...
5675

5776
class FastChildWatcher(BaseChildWatcher):
5877
def __enter__(self: Self) -> Self: ...
78+
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
79+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
80+
def remove_child_handler(self, pid: int) -> bool: ...
5981

6082
class _UnixSelectorEventLoop(BaseSelectorEventLoop):
6183
if sys.version_info < (3, 7):
@@ -86,8 +108,39 @@ if sys.platform != "win32":
86108
) -> None: ...
87109

88110
class MultiLoopChildWatcher(AbstractChildWatcher):
111+
def __init__(self) -> None: ...
112+
def is_active(self) -> bool: ...
113+
def close(self) -> None: ...
89114
def __enter__(self: Self) -> Self: ...
115+
def __exit__(
116+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
117+
) -> None: ...
118+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
119+
def remove_child_handler(self, pid: int) -> bool: ...
120+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
90121

91122
class ThreadedChildWatcher(AbstractChildWatcher):
123+
def __init__(self) -> None: ...
124+
def is_active(self) -> Literal[True]: ...
125+
def close(self) -> None: ...
92126
def __enter__(self: Self) -> Self: ...
127+
def __exit__(
128+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
129+
) -> None: ...
93130
def __del__(self, _warn: _Warn = ...) -> None: ...
131+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
132+
def remove_child_handler(self, pid: int) -> bool: ...
133+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
134+
135+
if sys.version_info >= (3, 9):
136+
class PidfdChildWatcher(AbstractChildWatcher):
137+
def __init__(self) -> None: ...
138+
def __enter__(self: Self) -> Self: ...
139+
def __exit__(
140+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
141+
) -> None: ...
142+
def is_active(self) -> bool: ...
143+
def close(self) -> None: ...
144+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
145+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
146+
def remove_child_handler(self, pid: int) -> bool: ...

tests/stubtest_allowlists/darwin-py310.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ _curses.color_pair
33
curses.color_pair
44

55
# Exists at runtime, but missing from stubs
6-
asyncio.PidfdChildWatcher
7-
asyncio.unix_events.PidfdChildWatcher
86
mmap.MADV_FREE
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
_?curses.A_ITALIC
22

33
# Exists at runtime, but missing from stubs
4-
asyncio.PidfdChildWatcher
5-
asyncio.unix_events.PidfdChildWatcher
64
mmap.MADV_FREE

tests/stubtest_allowlists/linux-py310.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ signal.sigwaitinfo
1818
select.epoll.register
1919

2020
# Exists at runtime, but missing from stubs
21-
asyncio.PidfdChildWatcher
22-
asyncio.unix_events.PidfdChildWatcher
2321
os.EFD_CLOEXEC
2422
os.EFD_NONBLOCK
2523
os.EFD_SEMAPHORE

tests/stubtest_allowlists/linux-py39.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
select.epoll.register
33

44
# Exists at runtime, but missing from stubs
5-
asyncio.PidfdChildWatcher
6-
asyncio.unix_events.PidfdChildWatcher
75
os.copy_file_range
86
os.pidfd_open
97
posix.copy_file_range

0 commit comments

Comments
 (0)