Mark stub-only private symbols as @type_check_only in third-party stubs (#14545)

This commit is contained in:
Brian Schubert
2025-08-08 11:29:48 +02:00
committed by GitHub
parent a358dc24e8
commit 81c8fcb2e6
131 changed files with 334 additions and 147 deletions
@@ -2,7 +2,7 @@ from _typeshed import Incomplete
from collections.abc import Callable
from logging import Logger
from threading import Thread
from typing import Any, Literal, Protocol, TypedDict, TypeVar, overload
from typing import Any, Literal, Protocol, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import ParamSpec, TypeAlias, Unpack
from flask import Flask
@@ -16,12 +16,15 @@ _R_co = TypeVar("_R_co", covariant=True)
_ExceptionHandler: TypeAlias = Callable[[BaseException], _R_co]
_Handler: TypeAlias = Callable[_P, _R_co]
@type_check_only
class _HandlerDecorator(Protocol):
def __call__(self, handler: _Handler[_P, _R_co]) -> _Handler[_P, _R_co]: ...
@type_check_only
class _ExceptionHandlerDecorator(Protocol):
def __call__(self, exception_handler: _ExceptionHandler[_R_co]) -> _ExceptionHandler[_R_co]: ...
@type_check_only
class _SocketIOServerOptions(TypedDict, total=False):
client_manager: Incomplete
logger: Logger | bool
@@ -29,6 +32,7 @@ class _SocketIOServerOptions(TypedDict, total=False):
async_handlers: bool
always_connect: bool
@type_check_only
class _EngineIOServerConfig(TypedDict, total=False):
async_mode: Literal["threading", "eventlet", "gevent", "gevent_uwsgi"]
ping_interval: float | tuple[float, float] # seconds
@@ -43,6 +47,7 @@ class _EngineIOServerConfig(TypedDict, total=False):
monitor_clients: bool
engineio_logger: Logger | bool
@type_check_only
class _SocketIOKwargs(_SocketIOServerOptions, _EngineIOServerConfig): ...
class SocketIO:
@@ -1,10 +1,11 @@
from _typeshed import Incomplete
from collections.abc import Callable
from typing import Any, Protocol, TypeVar
from typing import Any, Protocol, TypeVar, type_check_only
_T = TypeVar("_T")
# at runtime, socketio.namespace.BaseNamespace, but socketio isn't py.typed
@type_check_only
class _BaseNamespace(Protocol):
def is_asyncio_based(self) -> bool: ...
def trigger_event(self, event: str, *args): ...
@@ -1,9 +1,10 @@
from _typeshed import Incomplete
from typing import Any, TypedDict
from typing import Any, TypedDict, type_check_only
from flask import Flask
from flask.testing import FlaskClient
@type_check_only
class _Packet(TypedDict):
name: str
args: Any