Skip to content

Commit 0bdeabc

Browse files
committed
fix: protocol -> type alias
1 parent bbc50ed commit 0bdeabc

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

src/socketio-stubs/_types.pyi

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from collections.abc import Mapping, Sequence
1+
from collections.abc import Callable, Mapping, Sequence
22
from contextlib import AbstractAsyncContextManager, AbstractContextManager
33
from threading import Event as ThreadingEvent
44
from types import ModuleType
5-
from typing import Any, Literal, Protocol, TypeAlias, overload
5+
from typing import Any, Literal, TypeAlias, overload
66

77
import engineio
88
from _typeshed import Incomplete
@@ -19,7 +19,7 @@ from typing_extensions import NotRequired, Required, TypedDict
1919
JsonType: TypeAlias = (
2020
str | int | float | bool | None | Sequence[JsonType] | Mapping[str, JsonType]
2121
)
22-
DataType: TypeAlias = str | bytes | Sequence[JsonType] | Mapping[JsonType, JsonType]
22+
DataType: TypeAlias = str | bytes | Sequence[JsonType] | Mapping[str, JsonType]
2323
TransportType: TypeAlias = Literal["websocket", "polling"]
2424
SocketIOModeType: TypeAlias = Literal["development", "production"]
2525
SyncAsyncModeType: TypeAlias = Literal[
@@ -210,32 +210,13 @@ class JsonModule(ModuleType):
210210

211211
## handlers
212212

213-
class ServerConnectHandler(Protocol):
214-
def __call__(self, sid: str, environ: Mapping[str, Any]) -> Any: ...
215-
216-
class ServerConnectHandlerWithData(Protocol):
217-
def __call__(self, sid: str, environ: Mapping[str, Any], data: Any) -> Any: ...
218-
219-
class ServerDisconnectHandler(Protocol):
220-
def __call__(self, sid: str, reason: engineio.Server.reason) -> Any: ...
221-
222-
class ServerDisconnectLegacyHandler(Protocol):
223-
def __call__(self, sid: str) -> Any: ...
224-
225-
class ClientConnectHandler(Protocol):
226-
def __call__(self) -> Any: ...
227-
228-
class ClientDisconnectHandler(Protocol):
229-
def __call__(self, reason: engineio.Client.reason) -> Any: ...
230-
231-
class ClientDisconnectLegacyHandler(Protocol):
232-
def __call__(self) -> Any: ...
233-
234-
class ClientConnectErrorHandler(Protocol):
235-
def __call__(self, data: Any) -> Any: ...
236-
237-
class CatchAllHandler(Protocol):
238-
def __call__(self, event: str, sid: str, data: Any) -> Any: ...
239-
240-
class EventHandler(Protocol):
241-
def __call__(self, sid: str, data: Any) -> Any: ...
213+
ServerConnectHandler: TypeAlias = Callable[[str, dict[str, Any]], Any]
214+
ServerConnectHandlerWithData: TypeAlias = Callable[[str, dict[str, Any], Any], Any]
215+
ServerDisconnectHandler: TypeAlias = Callable[[str, engineio.Server.reason], Any]
216+
ServerDisconnectLegacyHandler: TypeAlias = Callable[[str], Any]
217+
ClientConnectHandler: TypeAlias = Callable[[], Any]
218+
ClientDisconnectHandler: TypeAlias = Callable[[engineio.Client.reason], Any]
219+
ClientDisconnectLegacyHandler: TypeAlias = Callable[[], Any]
220+
ClientConnectErrorHandler: TypeAlias = Callable[[Any], Any]
221+
CatchAllHandler: TypeAlias = Callable[[str, str, Any], Any]
222+
EventHandler: TypeAlias = Callable[[str, Any], DataType | tuple[DataType, ...] | None]

0 commit comments

Comments
 (0)