1
1
import sys
2
2
import types
3
3
from _typeshed import Self
4
+ from abc import ABCMeta , abstractmethod
4
5
from socket import socket
5
6
from typing import Any , Callable
7
+ from typing_extensions import Literal
6
8
7
9
from .base_events import Server
8
10
from .events import AbstractEventLoop , BaseDefaultEventLoopPolicy , _ProtocolFactory , _SSLContext
@@ -12,13 +14,20 @@ from .selector_events import BaseSelectorEventLoop
12
14
# but other parts of typeshed need this defintion.
13
15
# So, it is special cased.
14
16
class AbstractChildWatcher :
17
+ @abstractmethod
15
18
def add_child_handler (self , pid : int , callback : Callable [..., Any ], * args : Any ) -> None : ...
19
+ @abstractmethod
16
20
def remove_child_handler (self , pid : int ) -> bool : ...
21
+ @abstractmethod
17
22
def attach_loop (self , loop : AbstractEventLoop | None ) -> None : ...
23
+ @abstractmethod
18
24
def close (self ) -> None : ...
25
+ @abstractmethod
19
26
def __enter__ (self : Self ) -> Self : ...
27
+ @abstractmethod
20
28
def __exit__ (self , typ : type [BaseException ] | None , exc : BaseException | None , tb : types .TracebackType | None ) -> None : ...
21
29
if sys .version_info >= (3 , 8 ):
30
+ @abstractmethod
22
31
def is_active (self ) -> bool : ...
23
32
24
33
if sys .platform != "win32" :
@@ -48,14 +57,27 @@ if sys.platform != "win32":
48
57
else :
49
58
__all__ = ["SelectorEventLoop" , "AbstractChildWatcher" , "SafeChildWatcher" , "FastChildWatcher" , "DefaultEventLoopPolicy" ]
50
59
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 ):
52
63
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 : ...
53
69
54
70
class SafeChildWatcher (BaseChildWatcher ):
55
71
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 : ...
56
75
57
76
class FastChildWatcher (BaseChildWatcher ):
58
77
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 : ...
59
81
60
82
class _UnixSelectorEventLoop (BaseSelectorEventLoop ):
61
83
if sys .version_info < (3 , 7 ):
@@ -86,8 +108,39 @@ if sys.platform != "win32":
86
108
) -> None : ...
87
109
88
110
class MultiLoopChildWatcher (AbstractChildWatcher ):
111
+ def __init__ (self ) -> None : ...
112
+ def is_active (self ) -> bool : ...
113
+ def close (self ) -> None : ...
89
114
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 : ...
90
121
91
122
class ThreadedChildWatcher (AbstractChildWatcher ):
123
+ def __init__ (self ) -> None : ...
124
+ def is_active (self ) -> Literal [True ]: ...
125
+ def close (self ) -> None : ...
92
126
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 : ...
93
130
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 : ...
0 commit comments