11from _typeshed import Incomplete
22from collections .abc import Callable
3+ from logging import Logger
34from threading import Thread
4- from typing import Any , Protocol , TypeVar , overload
5- from typing_extensions import ParamSpec , TypeAlias
5+ from typing import Any , Literal , Protocol , TypedDict , TypeVar , overload
6+ from typing_extensions import ParamSpec , TypeAlias , Unpack
67
78from flask import Flask
89from flask .testing import FlaskClient
@@ -21,7 +22,32 @@ class _HandlerDecorator(Protocol):
2122class _ExceptionHandlerDecorator (Protocol ):
2223 def __call__ (self , exception_handler : _ExceptionHandler [_R_co ]) -> _ExceptionHandler [_R_co ]: ...
2324
25+ class _SocketIOServerOptions (TypedDict , total = False ):
26+ client_manager : Incomplete
27+ logger : Logger | bool
28+ json : Incomplete
29+ async_handlers : bool
30+ always_connect : bool
31+
32+ class _EngineIOServerConfig (TypedDict , total = False ):
33+ async_mode : Literal ["threading" , "eventlet" , "gevent" , "gevent_uwsgi" ]
34+ ping_interval : float | tuple [float , float ] # seconds
35+ ping_timeout : float # seconds
36+ max_http_buffer_size : int
37+ allow_upgrades : bool
38+ http_compression : bool
39+ compression_threshold : int
40+ cookie : str | dict [str , Any ] | None
41+ cors_allowed_origins : str | list [str ]
42+ cors_credentials : bool
43+ monitor_clients : bool
44+ engineio_logger : Logger | bool
45+
46+ class _SocketIOKwargs (_SocketIOServerOptions , _EngineIOServerConfig ): ...
47+
2448class SocketIO :
49+ # This is an alias for `socketio.Server.reason` in `python-socketio`, which is not typed.
50+ reason : Incomplete
2551 # Many instance attributes are deliberately not included here,
2652 # as the maintainer of Flask-SocketIO considers them private, internal details:
2753 # https://github.com/python/typeshed/pull/10735#discussion_r1330768869
@@ -35,7 +61,7 @@ class SocketIO:
3561 channel : str = "flask-socketio" ,
3662 path : str = "socket.io" ,
3763 resource : str = "socket.io" ,
38- ** kwargs , # TODO: Socket.IO server options, Engine.IO server config
64+ ** kwargs : Unpack [ _SocketIOKwargs ],
3965 ) -> None : ...
4066 def init_app (
4167 self ,
@@ -47,7 +73,7 @@ class SocketIO:
4773 channel : str = "flask-socketio" ,
4874 path : str = "socket.io" ,
4975 resource : str = "socket.io" ,
50- ** kwargs , # TODO: Socket.IO server options, Engine.IO server config: ...
76+ ** kwargs : Unpack [ _SocketIOKwargs ],
5177 ) -> None : ...
5278 def on (self , message : str , namespace : str | None = None ) -> _HandlerDecorator : ...
5379 def on_error (self , namespace : str | None = None ) -> _ExceptionHandlerDecorator : ...
0 commit comments