Skip to content

Fix paho-mqtt typing errors #8878

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

Merged
merged 7 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
92 changes: 43 additions & 49 deletions stubs/paho-mqtt/paho/mqtt/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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): ...
Expand Down Expand Up @@ -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 = ...,
Expand All @@ -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(
Expand Down Expand Up @@ -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]: ...
Expand All @@ -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: ...
Expand Down
7 changes: 5 additions & 2 deletions stubs/paho-mqtt/paho/mqtt/publish.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ssl
from collections.abc import Iterable
from typing_extensions import NotRequired, TypeAlias, TypedDict

Expand All @@ -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]

Expand Down