diff --git a/stubs/Flask-SocketIO/flask_socketio/__init__.pyi b/stubs/Flask-SocketIO/flask_socketio/__init__.pyi index 68fdd4cf9583..1b20806fda6c 100644 --- a/stubs/Flask-SocketIO/flask_socketio/__init__.pyi +++ b/stubs/Flask-SocketIO/flask_socketio/__init__.pyi @@ -1,8 +1,9 @@ from _typeshed import Incomplete from collections.abc import Callable +from logging import Logger from threading import Thread -from typing import Any, Protocol, TypeVar, overload -from typing_extensions import ParamSpec, TypeAlias +from typing import Any, Literal, Protocol, TypedDict, TypeVar, overload +from typing_extensions import ParamSpec, TypeAlias, Unpack from flask import Flask from flask.testing import FlaskClient @@ -21,7 +22,32 @@ class _HandlerDecorator(Protocol): class _ExceptionHandlerDecorator(Protocol): def __call__(self, exception_handler: _ExceptionHandler[_R_co]) -> _ExceptionHandler[_R_co]: ... +class _SocketIOServerOptions(TypedDict, total=False): + client_manager: Incomplete + logger: Logger | bool + json: Incomplete + async_handlers: bool + always_connect: bool + +class _EngineIOServerConfig(TypedDict, total=False): + async_mode: Literal["threading", "eventlet", "gevent", "gevent_uwsgi"] + ping_interval: float | tuple[float, float] # seconds + ping_timeout: float # seconds + max_http_buffer_size: int + allow_upgrades: bool + http_compression: bool + compression_threshold: int + cookie: str | dict[str, Any] | None + cors_allowed_origins: str | list[str] + cors_credentials: bool + monitor_clients: bool + engineio_logger: Logger | bool + +class _SocketIOKwargs(_SocketIOServerOptions, _EngineIOServerConfig): ... + class SocketIO: + # This is an alias for `socketio.Server.reason` in `python-socketio`, which is not typed. + reason: Incomplete # Many instance attributes are deliberately not included here, # as the maintainer of Flask-SocketIO considers them private, internal details: # https://github.com/python/typeshed/pull/10735#discussion_r1330768869 @@ -35,7 +61,7 @@ class SocketIO: channel: str = "flask-socketio", path: str = "socket.io", resource: str = "socket.io", - **kwargs, # TODO: Socket.IO server options, Engine.IO server config + **kwargs: Unpack[_SocketIOKwargs], ) -> None: ... def init_app( self, @@ -47,7 +73,7 @@ class SocketIO: channel: str = "flask-socketio", path: str = "socket.io", resource: str = "socket.io", - **kwargs, # TODO: Socket.IO server options, Engine.IO server config: ... + **kwargs: Unpack[_SocketIOKwargs], ) -> None: ... def on(self, message: str, namespace: str | None = None) -> _HandlerDecorator: ... def on_error(self, namespace: str | None = None) -> _ExceptionHandlerDecorator: ...