Skip to content

Commit 2609fa3

Browse files
committed
asyncio.unix_events: Make AbstractChildWatcher abstract, add PidfdChildWatcher
1 parent 000b466 commit 2609fa3

File tree

5 files changed

+50
-9
lines changed

5 files changed

+50
-9
lines changed

stdlib/asyncio/unix_events.pyi

Lines changed: 50 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,23 @@ if sys.platform != "win32":
4857
else:
4958
__all__ = ["SelectorEventLoop", "AbstractChildWatcher", "SafeChildWatcher", "FastChildWatcher", "DefaultEventLoopPolicy"]
5059

51-
class BaseChildWatcher(AbstractChildWatcher):
60+
class BaseChildWatcher(AbstractChildWatcher, metaclass=ABCMeta):
5261
def __init__(self) -> None: ...
62+
def close(self) -> None: ...
63+
def is_active(self) -> bool: ...
64+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
5365

5466
class SafeChildWatcher(BaseChildWatcher):
5567
def __enter__(self: Self) -> Self: ...
68+
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
69+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
70+
def remove_child_handler(self, pid: int) -> bool: ...
5671

5772
class FastChildWatcher(BaseChildWatcher):
5873
def __enter__(self: Self) -> Self: ...
74+
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
75+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
76+
def remove_child_handler(self, pid: int) -> bool: ...
5977

6078
class _UnixSelectorEventLoop(BaseSelectorEventLoop):
6179
if sys.version_info < (3, 7):
@@ -86,8 +104,39 @@ if sys.platform != "win32":
86104
) -> None: ...
87105

88106
class MultiLoopChildWatcher(AbstractChildWatcher):
107+
def __init__(self) -> None: ...
108+
def is_active(self) -> bool: ...
109+
def close(self) -> None: ...
89110
def __enter__(self: Self) -> Self: ...
111+
def __exit__(
112+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
113+
) -> None: ...
114+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
115+
def remove_child_handler(self, pid: int) -> bool: ...
116+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
90117

91118
class ThreadedChildWatcher(AbstractChildWatcher):
119+
def __init__(self) -> None: ...
120+
def is_active(self) -> Literal[True]: ...
121+
def close(self) -> None: ...
92122
def __enter__(self: Self) -> Self: ...
123+
def __exit__(
124+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
125+
) -> None: ...
93126
def __del__(self, _warn: _Warn = ...) -> None: ...
127+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
128+
def remove_child_handler(self, pid: int) -> bool: ...
129+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
130+
131+
if sys.version_info >= (3, 9):
132+
class PidfdChildWatcher(AbstractChildWatcher):
133+
def __init__(self) -> None: ...
134+
def __enter__(self: Self) -> Self: ...
135+
def __exit__(
136+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
137+
) -> None: ...
138+
def is_active(self) -> bool: ...
139+
def close(self) -> None: ...
140+
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
141+
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
142+
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)