@@ -3,9 +3,9 @@ from _typeshed import FileDescriptor, StrOrBytesPath
33from collections .abc import Callable
44from types import TracebackType
55from typing import Any , Protocol , overload
6- from typing_extensions import Concatenate , Literal , ParamSpec , TypeAlias
6+ from typing_extensions import Literal , TypeAlias , TypeVarTuple , Unpack
77
8- _P = ParamSpec ( "_P " )
8+ _Ts = TypeVarTuple ( "_Ts " )
99
1010# gevent uses zope.interface interanlly which does not work well with type checkers
1111# partially due to the odd call signatures without self and partially due to them
@@ -62,16 +62,13 @@ class _Loop(Protocol): # noqa: Y046
6262
6363 def async_ (self , ref : bool = True , priority : int | None = None ) -> _AsyncWatcher : ...
6464 def stat (self , path : str , interval : float = 0.0 , ref : bool = True , priority : bool | None = ...) -> _StatWatcher : ...
65- # These technically don't allow the functions arguments to be passed in as kwargs
66- # but there's no way to express that yet with ParamSpec, however, we would still like
67- # to verify that the arguments match
68- def run_callback (self , func : Callable [_P , Any ], * args : _P .args , ** _ : _P .kwargs ) -> _Callback : ...
69- def run_callback_threadsafe (self , func : Callable [_P , Any ], * args : _P .args , ** _ : _P .kwargs ) -> _Callback : ...
65+ def run_callback (self , func : Callable [[Unpack [_Ts ]], Any ], * args : Unpack [_Ts ]) -> _Callback : ...
66+ def run_callback_threadsafe (self , func : Callable [[Unpack [_Ts ]], Any ], * args : Unpack [_Ts ]) -> _Callback : ...
7067 def fileno (self ) -> FileDescriptor | None : ...
7168
7269class _Watcher (Protocol ):
7370 # while IWatcher allows for kwargs the actual implementation does not...
74- def start (self , callback : Callable [_P , Any ], * args : _P . args , ** _ : _P . kwargs ) -> None : ...
71+ def start (self , callback : Callable [[ Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] ) -> None : ...
7572 def stop (self ) -> None : ...
7673 def close (self ) -> None : ...
7774
@@ -80,23 +77,23 @@ class _TimerWatcher(_Watcher, Protocol):
8077 # this has one specific allowed keyword argument, if it is given we don't try to check
8178 # the passed in arguments, but if it isn't passed in, then we do.
8279 @overload
83- def start (self , callback : Callable [... , Any ], * args : Any , update : bool ) -> None : ...
80+ def start (self , callback : Callable [[ Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] , update : bool ) -> None : ...
8481 @overload
85- def start (self , callback : Callable [_P , Any ], * args : _P . args , ** _ : _P . kwargs ) -> None : ...
82+ def start (self , callback : Callable [[ Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] ) -> None : ...
8683 @overload
87- def again (self , callback : Callable [... , Any ], * args : Any , update : bool ) -> None : ...
84+ def again (self , callback : Callable [[ Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] , update : bool ) -> None : ...
8885 @overload
89- def again (self , callback : Callable [_P , Any ], * args : _P . args , ** _ : _P . kwargs ) -> None : ...
86+ def again (self , callback : Callable [[ Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] ) -> None : ...
9087
9188# this matches Intersection[_Watcher, IoMixin]
9289class _IoWatcher (_Watcher , Protocol ):
9390 EVENT_MASK : int
9491 # pass_events means the first argument of the callback needs to be an integer, but we can't
9592 # type check the other passed in args in this case
9693 @overload
97- def start (self , callback : Callable [Concatenate [int , _P ] , Any ], * args : Any , pass_events : Literal [True ]) -> None : ...
94+ def start (self , callback : Callable [[int , Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] , pass_events : Literal [True ]) -> None : ...
9895 @overload
99- def start (self , callback : Callable [_P , Any ], * args : _P . args , ** _ : _P . kwargs ) -> None : ...
96+ def start (self , callback : Callable [[ Unpack [ _Ts ]] , Any ], * args : Unpack [ _Ts ] ) -> None : ...
10097
10198# this matches Intersection[_Watcher, ChildMixin]
10299class _ChildWatcher (_Watcher , Protocol ):
0 commit comments