mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Fix paho-mqtt typing errors (#8878)
This commit is contained in:
@@ -3,8 +3,8 @@ import socket as _socket
|
||||
import ssl as _ssl
|
||||
import time
|
||||
import types
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import Any, TypeVar
|
||||
from collections.abc import Callable
|
||||
from typing import Any, Optional, TypeVar
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from .matcher import MQTTMatcher as MQTTMatcher
|
||||
@@ -90,29 +90,21 @@ _Socket: TypeAlias = _socket.socket | _ssl.SSLSocket | Any
|
||||
_Payload: TypeAlias = str | bytes | bytearray | float
|
||||
_ExtraHeader: TypeAlias = dict[str, str] | Callable[[dict[str, str]], dict[str, str]]
|
||||
_OnLog: TypeAlias = Callable[[Client, _UserData, int, str], object]
|
||||
_OnConnect = TypeVar(
|
||||
"_OnConnect",
|
||||
Callable[[Client, _UserData, dict[str, int], int], object],
|
||||
Callable[[Client, _UserData, dict[str, int], ReasonCodes, Properties | None], object],
|
||||
)
|
||||
_OnConnect: TypeAlias = Callable[[Client, _UserData, dict[str, int], int], object]
|
||||
_OnConnectV5: TypeAlias = Callable[[Client, _UserData, dict[str, int], ReasonCodes, Optional[Properties]], object]
|
||||
_TOnConnect = TypeVar("_TOnConnect", _OnConnect, _OnConnectV5)
|
||||
_OnConnectFail: TypeAlias = Callable[[Client, _UserData], object]
|
||||
_OnSubscribe = TypeVar(
|
||||
"_OnSubscribe",
|
||||
Callable[[Client, _UserData, int, Iterable[int]], object],
|
||||
Callable[[Client, _UserData, Iterable[ReasonCodes], Iterable[Properties]], object],
|
||||
)
|
||||
_OnSubscribe: TypeAlias = Callable[[Client, _UserData, int, tuple[int]], object]
|
||||
_OnSubscribeV5: TypeAlias = Callable[[Client, _UserData, int, list[ReasonCodes], Properties], object]
|
||||
_TOnSubscribe = TypeVar("_TOnSubscribe", _OnSubscribe, _OnSubscribeV5)
|
||||
_OnMessage: TypeAlias = Callable[[Client, _UserData, MQTTMessage], object]
|
||||
_OnPublish: TypeAlias = Callable[[Client, _UserData, int], object]
|
||||
_OnUnsubscribe = TypeVar(
|
||||
"_OnUnsubscribe",
|
||||
Callable[[Client, _UserData, int], object],
|
||||
Callable[[Client, _UserData, int, Iterable[Properties], Iterable[ReasonCodes]], object],
|
||||
)
|
||||
_OnDisconnect = TypeVar(
|
||||
"_OnDisconnect",
|
||||
Callable[[Client, _UserData, int], object],
|
||||
Callable[[Client, _UserData, int, ReasonCodes | None, Properties | None], object],
|
||||
)
|
||||
_OnUnsubscribe: TypeAlias = Callable[[Client, _UserData, int], object]
|
||||
_OnUnsubscribeV5: TypeAlias = Callable[[Client, _UserData, int, Properties, list[ReasonCodes] | ReasonCodes], object]
|
||||
_TOnUnsubscribe = TypeVar("_TOnUnsubscribe", _OnUnsubscribe, _OnUnsubscribeV5)
|
||||
_OnDisconnect: TypeAlias = Callable[[Client, _UserData, int], object]
|
||||
_OnDisconnectV5: TypeAlias = Callable[[Client, _UserData, Optional[ReasonCodes], Optional[Properties]], object]
|
||||
_TOnDisconnect = TypeVar("_TOnDisconnect", _OnDisconnect, _OnDisconnectV5)
|
||||
_OnSocket: TypeAlias = Callable[[Client, _UserData, _Socket | WebsocketWrapper | None], object]
|
||||
|
||||
class WebsocketConnectionError(ValueError): ...
|
||||
@@ -155,7 +147,7 @@ class Client:
|
||||
suppress_exceptions: bool
|
||||
def __init__(
|
||||
self,
|
||||
client_id: str = ...,
|
||||
client_id: str | None = ...,
|
||||
clean_session: bool | None = ...,
|
||||
userdata: _UserData | None = ...,
|
||||
protocol: int = ...,
|
||||
@@ -177,7 +169,7 @@ class Client:
|
||||
keyfile_password: _ssl._PasswordType | None = ...,
|
||||
) -> None: ...
|
||||
def tls_insecure_set(self, value: bool) -> None: ...
|
||||
def proxy_set(self, **proxy_args: str | int) -> None: ...
|
||||
def proxy_set(self, **proxy_args: Any) -> None: ...
|
||||
def enable_logger(self, logger: logging.Logger | None = ...) -> None: ...
|
||||
def disable_logger(self) -> None: ...
|
||||
def connect(
|
||||
@@ -245,62 +237,62 @@ class Client:
|
||||
@property
|
||||
def on_log(self) -> _OnLog | None: ...
|
||||
@on_log.setter
|
||||
def on_log(self, func: _OnLog) -> None: ...
|
||||
def on_log(self, func: _OnLog | None) -> None: ...
|
||||
def log_callback(self) -> Callable[[_OnLog], _OnLog]: ...
|
||||
@property
|
||||
def on_connect(self) -> _OnConnect | None: ...
|
||||
def on_connect(self) -> _OnConnect | _OnConnectV5 | None: ...
|
||||
@on_connect.setter
|
||||
def on_connect(self, func: _OnConnect) -> None: ...
|
||||
def connect_callback(self) -> Callable[[_OnConnect], _OnConnect]: ...
|
||||
def on_connect(self, func: _OnConnect | _OnConnectV5 | None) -> None: ...
|
||||
def connect_callback(self) -> Callable[[_TOnConnect], _TOnConnect]: ...
|
||||
@property
|
||||
def on_connect_fail(self) -> _OnConnectFail | None: ...
|
||||
@on_connect_fail.setter
|
||||
def on_connect_fail(self, func: _OnConnectFail) -> None: ...
|
||||
def on_connect_fail(self, func: _OnConnectFail | None) -> None: ...
|
||||
def connect_fail_callback(self) -> Callable[[_OnConnectFail], _OnConnectFail]: ...
|
||||
@property
|
||||
def on_subscribe(self) -> _OnSubscribe | None: ...
|
||||
def on_subscribe(self) -> _OnSubscribe | _OnSubscribeV5 | None: ...
|
||||
@on_subscribe.setter
|
||||
def on_subscribe(self, func: _OnSubscribe) -> None: ...
|
||||
def subscribe_callback(self) -> Callable[[_OnSubscribe], _OnSubscribe]: ...
|
||||
def on_subscribe(self, func: _OnSubscribe | _OnSubscribeV5 | None) -> None: ...
|
||||
def subscribe_callback(self) -> Callable[[_TOnSubscribe], _TOnSubscribe]: ...
|
||||
@property
|
||||
def on_message(self) -> _OnMessage | None: ...
|
||||
@on_message.setter
|
||||
def on_message(self, func: _OnMessage) -> None: ...
|
||||
def on_message(self, func: _OnMessage | None) -> None: ...
|
||||
def message_callback(self) -> Callable[[_OnMessage], _OnMessage]: ...
|
||||
@property
|
||||
def on_publish(self) -> _OnPublish | None: ...
|
||||
@on_publish.setter
|
||||
def on_publish(self, func: _OnPublish) -> None: ...
|
||||
def on_publish(self, func: _OnPublish | None) -> None: ...
|
||||
def publish_callback(self) -> Callable[[_OnPublish], _OnPublish]: ...
|
||||
@property
|
||||
def on_unsubscribe(self) -> _OnUnsubscribe | None: ...
|
||||
def on_unsubscribe(self) -> _OnUnsubscribe | _OnUnsubscribeV5 | None: ...
|
||||
@on_unsubscribe.setter
|
||||
def on_unsubscribe(self, func: _OnUnsubscribe) -> None: ...
|
||||
def unsubscribe_callback(self) -> Callable[[_OnUnsubscribe], _OnUnsubscribe]: ...
|
||||
def on_unsubscribe(self, func: _OnUnsubscribe | _OnUnsubscribeV5 | None) -> None: ...
|
||||
def unsubscribe_callback(self) -> Callable[[_TOnUnsubscribe], _TOnUnsubscribe]: ...
|
||||
@property
|
||||
def on_disconnect(self) -> _OnDisconnect: ...
|
||||
def on_disconnect(self) -> _OnDisconnect | _OnDisconnectV5 | None: ...
|
||||
@on_disconnect.setter
|
||||
def on_disconnect(self, func: _OnDisconnect) -> None: ...
|
||||
def disconnect_callback(self) -> Callable[[_OnDisconnect], _OnDisconnect]: ...
|
||||
def on_disconnect(self, func: _OnDisconnect | _OnDisconnectV5 | None) -> None: ...
|
||||
def disconnect_callback(self) -> Callable[[_TOnDisconnect], _TOnDisconnect]: ...
|
||||
@property
|
||||
def on_socket_open(self) -> _OnSocket: ...
|
||||
def on_socket_open(self) -> _OnSocket | None: ...
|
||||
@on_socket_open.setter
|
||||
def on_socket_open(self, func: _OnSocket) -> None: ...
|
||||
def on_socket_open(self, func: _OnSocket | None) -> None: ...
|
||||
def socket_open_callback(self) -> Callable[[_OnSocket], _OnSocket]: ...
|
||||
@property
|
||||
def on_socket_close(self) -> _OnSocket: ...
|
||||
def on_socket_close(self) -> _OnSocket | None: ...
|
||||
@on_socket_close.setter
|
||||
def on_socket_close(self, func: _OnSocket) -> None: ...
|
||||
def on_socket_close(self, func: _OnSocket | None) -> None: ...
|
||||
def socket_close_callback(self) -> Callable[[_OnSocket], _OnSocket]: ...
|
||||
@property
|
||||
def on_socket_register_write(self) -> _OnSocket: ...
|
||||
def on_socket_register_write(self) -> _OnSocket | None: ...
|
||||
@on_socket_register_write.setter
|
||||
def on_socket_register_write(self, func: _OnSocket) -> None: ...
|
||||
def on_socket_register_write(self, func: _OnSocket | None) -> None: ...
|
||||
def socket_register_write_callback(self) -> Callable[[_OnSocket], _OnSocket]: ...
|
||||
@property
|
||||
def on_socket_unregister_write(self) -> _OnSocket: ...
|
||||
def on_socket_unregister_write(self) -> _OnSocket | None: ...
|
||||
@on_socket_unregister_write.setter
|
||||
def on_socket_unregister_write(self, func: _OnSocket) -> None: ...
|
||||
def on_socket_unregister_write(self, func: _OnSocket | None) -> None: ...
|
||||
def socket_unregister_write_callback(self) -> Callable[[_OnSocket], _OnSocket]: ...
|
||||
def message_callback_add(self, sub: str, callback: _OnMessage) -> None: ...
|
||||
def topic_callback(self, sub: str) -> Callable[[_OnMessage], _OnMessage]: ...
|
||||
@@ -314,7 +306,9 @@ class WebsocketWrapper:
|
||||
OPCODE_PING: int
|
||||
OPCODE_PONG: int
|
||||
connected: bool
|
||||
def __init__(self, socket: _Socket, host: str, port: int, is_ssl: bool, path: str, extra_headers: _ExtraHeader) -> None: ...
|
||||
def __init__(
|
||||
self, socket: _Socket, host: str, port: int, is_ssl: bool, path: str, extra_headers: _ExtraHeader | None
|
||||
) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def recv(self, length: int) -> bytes | bytearray | None: ...
|
||||
def read(self, length: int) -> bytes | bytearray | None: ...
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import ssl
|
||||
from collections.abc import Iterable
|
||||
from typing_extensions import NotRequired, TypeAlias, TypedDict
|
||||
|
||||
@@ -17,14 +18,16 @@ class _TLS(TypedDict):
|
||||
ca_certs: str
|
||||
certfile: NotRequired[str]
|
||||
keyfile: NotRequired[str]
|
||||
tls_version: NotRequired[str]
|
||||
tls_version: NotRequired[ssl._SSLMethod]
|
||||
ciphers: NotRequired[str]
|
||||
insecure: NotRequired[str]
|
||||
cert_reqs: NotRequired[ssl.VerifyMode]
|
||||
keyfile_password: NotRequired[ssl._PasswordType]
|
||||
|
||||
class _Proxy(TypedDict):
|
||||
proxy_type: int
|
||||
proxy_addr: str
|
||||
proxy_rdns: NotRequired[str]
|
||||
proxy_rdns: NotRequired[bool]
|
||||
proxy_username: NotRequired[str]
|
||||
proxy_passwor: NotRequired[str]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user