1
1
from collections .abc import Callable , Container
2
2
from types import TracebackType
3
- from typing import Any , Generic , Literal , Protocol , type_check_only
4
- from typing_extensions import ParamSpec , Self , TypeAlias
3
+ from typing import Generic , Literal , Protocol , type_check_only
4
+ from typing_extensions import ParamSpec , Self , TypeAlias , TypeVarTuple , Unpack
5
5
6
6
from gevent ._types import _Loop
7
7
from gevent .pool import Pool
8
8
from gevent .socket import socket as _GeventSocket
9
9
from greenlet import greenlet
10
10
11
+ _Ts = TypeVarTuple ("_Ts" )
11
12
_P = ParamSpec ("_P" )
12
13
13
14
@type_check_only
@@ -16,7 +17,7 @@ class _SpawnFunc(Protocol):
16
17
17
18
_Spawner : TypeAlias = Pool | _SpawnFunc | int | Literal ["default" ] | None
18
19
19
- class BaseServer (Generic [_P ]):
20
+ class BaseServer (Generic [Unpack [ _Ts ] ]):
20
21
min_delay : float
21
22
max_delay : float
22
23
max_accept : int
@@ -28,27 +29,23 @@ class BaseServer(Generic[_P]):
28
29
family : int
29
30
address : str | tuple [str , int ]
30
31
socket : _GeventSocket
31
- handle : Callable [... , object ]
32
+ handle : Callable [[ Unpack [ _Ts ]] , object ]
32
33
def __init__ (
33
34
self ,
34
35
listener : _GeventSocket | tuple [str , int ] | str ,
35
- handle : Callable [_P , object ] | None = None ,
36
+ handle : Callable [[ Unpack [ _Ts ]] , object ] | None = None ,
36
37
spawn : _Spawner = "default" ,
37
38
) -> None : ...
38
39
def __enter__ (self ) -> Self : ...
39
40
def __exit__ (self , typ : type [BaseException ] | None , value : BaseException | None , tb : TracebackType | None , / ) -> None : ...
40
41
def set_listener (self , listener : _GeventSocket | tuple [str , int ] | str ) -> None : ...
41
42
def set_spawn (self , spawn : _Spawner ) -> None : ...
42
- def set_handle (self , handle : Callable [_P , object ]) -> None : ...
43
+ def set_handle (self , handle : Callable [[ Unpack [ _Ts ]] , object ]) -> None : ...
43
44
def start_accepting (self ) -> None : ...
44
45
def stop_accepting (self ) -> None : ...
45
- # neither of these accept keyword arguments, but if we omit them, then ParamSpec
46
- # won't match the arguments correctly
47
- def do_handle (self , * args : _P .args , ** _ : _P .kwargs ) -> None : ...
48
- def do_close (self , * args : _P .args , ** _ : _P .kwargs ) -> None : ...
49
- # we would like to return _P.args here, however pyright will complain
50
- # mypy doesn't seem to mind
51
- def do_read (self ) -> tuple [Any , ...] | None : ...
46
+ def do_handle (self , * args : Unpack [_Ts ]) -> None : ...
47
+ def do_close (self , * args : Unpack [_Ts ]) -> None : ...
48
+ def do_read (self ) -> tuple [Unpack [_Ts ]] | None : ...
52
49
def full (self ) -> bool : ...
53
50
@property
54
51
def server_host (self ) -> str | None : ...
0 commit comments