Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask-socketio 5.5 + add type of kwargs #13271

Merged
merged 6 commits into from
Dec 23, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions stubs/Flask-SocketIO/flask_socketio/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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 import Any, Literal, Protocol, TypedDict, TypeVar, overload
from typing_extensions import ParamSpec, TypeAlias

from flask import Flask
Expand All @@ -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: int # seconds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be a two-tuple "For advanced control, a two element tuple can be given, where the first number is the ping interval and the second is a grace period added by the server."

I also suspect it can be a float instead of an int but haven't verified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping_timeout: int # 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
Expand All @@ -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: _SocketIOKwargs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Unpack?

) -> None: ...
def init_app(
self,
Expand All @@ -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: _SocketIOKwargs,
) -> None: ...
def on(self, message: str, namespace: str | None = None) -> _HandlerDecorator: ...
def on_error(self, namespace: str | None = None) -> _ExceptionHandlerDecorator: ...
Expand Down
Loading