@@ -2,7 +2,7 @@ import sys
22from _typeshed import FileDescriptor , StrOrBytesPath
33from collections .abc import Callable
44from types import TracebackType
5- from typing import Any , Literal , Protocol , overload
5+ from typing import Any , Literal , Protocol , overload , type_check_only
66from typing_extensions import TypeAlias , TypeVarTuple , Unpack
77
88_Ts = TypeVarTuple ("_Ts" )
@@ -19,6 +19,7 @@ _Ts = TypeVarTuple("_Ts")
1919# properties and methods that are available on all event loops, so these have
2020# been added as well, instead of completely mirroring the internal interface
2121
22+ @type_check_only
2223class _Loop (Protocol ): # noqa: Y046
2324 @property
2425 def approx_timer_resolution (self ) -> float : ...
@@ -66,13 +67,15 @@ class _Loop(Protocol): # noqa: Y046
6667 def run_callback_threadsafe (self , func : Callable [[Unpack [_Ts ]], Any ], * args : Unpack [_Ts ]) -> _Callback : ...
6768 def fileno (self ) -> FileDescriptor | None : ...
6869
70+ @type_check_only
6971class _Watcher (Protocol ):
7072 # while IWatcher allows for kwargs the actual implementation does not...
7173 def start (self , callback : Callable [[Unpack [_Ts ]], Any ], * args : Unpack [_Ts ]) -> None : ...
7274 def stop (self ) -> None : ...
7375 def close (self ) -> None : ...
7476
7577# this matches Intersection[_Watcher, TimerMixin]
78+ @type_check_only
7679class _TimerWatcher (_Watcher , Protocol ):
7780 # this has one specific allowed keyword argument, if it is given we don't try to check
7881 # the passed in arguments, but if it isn't passed in, then we do.
@@ -86,6 +89,7 @@ class _TimerWatcher(_Watcher, Protocol):
8689 def again (self , callback : Callable [[Unpack [_Ts ]], Any ], * args : Unpack [_Ts ]) -> None : ...
8790
8891# this matches Intersection[_Watcher, IoMixin]
92+ @type_check_only
8993class _IoWatcher (_Watcher , Protocol ):
9094 EVENT_MASK : int
9195 # pass_events means the first argument of the callback needs to be an integer, but we can't
@@ -96,6 +100,7 @@ class _IoWatcher(_Watcher, Protocol):
96100 def start (self , callback : Callable [[Unpack [_Ts ]], Any ], * args : Unpack [_Ts ]) -> None : ...
97101
98102# this matches Intersection[_Watcher, ChildMixin]
103+ @type_check_only
99104class _ChildWatcher (_Watcher , Protocol ):
100105 @property
101106 def pid (self ) -> int : ...
@@ -105,18 +110,21 @@ class _ChildWatcher(_Watcher, Protocol):
105110 def rstatus (self ) -> int : ...
106111
107112# this matches Intersection[_Watcher, AsyncMixin]
113+ @type_check_only
108114class _AsyncWatcher (_Watcher , Protocol ):
109115 def send (self ) -> None : ...
110116 def send_ignoring_arg (self , ignored : object , / ) -> None : ...
111117 @property
112118 def pending (self ) -> bool : ...
113119
114120# all implementations return something of this shape
121+ @type_check_only
115122class _StatResult (Protocol ):
116123 @property
117124 def st_nlink (self ) -> int : ...
118125
119126# this matches Intersection[_Watcher, StatMixin]
127+ @type_check_only
120128class _StatWatcher (_Watcher , Protocol ):
121129 @property
122130 def path (self ) -> StrOrBytesPath : ...
@@ -127,6 +135,7 @@ class _StatWatcher(_Watcher, Protocol):
127135 @property
128136 def interval (self ) -> float : ...
129137
138+ @type_check_only
130139class _Callback (Protocol ):
131140 pending : bool
132141 def stop (self ) -> None : ...
@@ -137,6 +146,7 @@ _SockAddr: TypeAlias = _FullSockAddr | tuple[str, int]
137146_AddrinfoResult : TypeAlias = list [tuple [int , int , int , str , _SockAddr ]] # family, type, protocol, cname, sockaddr
138147_NameinfoResult : TypeAlias = tuple [str , str ]
139148
149+ @type_check_only
140150class _Resolver (Protocol ): # noqa: Y046
141151 def close (self ) -> None : ...
142152 def gethostbyname (self , hostname : str , family : int = 2 ) -> str : ...
0 commit comments