From e4209219e1138067355678822702dd39b53b4696 Mon Sep 17 00:00:00 2001 From: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:43:40 +0200 Subject: [PATCH 1/3] Add paho-mqtt stubs --- pyrightconfig.stricter.json | 1 + stubs/paho-mqtt/METADATA.toml | 4 + stubs/paho-mqtt/paho/__init__.pyi | 0 stubs/paho-mqtt/paho/mqtt/__init__.pyi | 1 + stubs/paho-mqtt/paho/mqtt/client.pyi | 321 ++++++++++++++++++ stubs/paho-mqtt/paho/mqtt/matcher.pyi | 11 + stubs/paho-mqtt/paho/mqtt/packettypes.pyi | 19 ++ stubs/paho-mqtt/paho/mqtt/properties.pyi | 38 +++ stubs/paho-mqtt/paho/mqtt/publish.pyi | 59 ++++ stubs/paho-mqtt/paho/mqtt/reasoncodes.pyi | 13 + stubs/paho-mqtt/paho/mqtt/subscribe.pyi | 40 +++ .../paho-mqtt/paho/mqtt/subscribeoptions.pyi | 25 ++ 12 files changed, 532 insertions(+) create mode 100644 stubs/paho-mqtt/METADATA.toml create mode 100644 stubs/paho-mqtt/paho/__init__.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/__init__.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/client.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/matcher.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/packettypes.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/properties.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/publish.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/reasoncodes.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/subscribe.pyi create mode 100644 stubs/paho-mqtt/paho/mqtt/subscribeoptions.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index ab8c96de2975..29fd2f4ec4b1 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -66,6 +66,7 @@ "stubs/pytz/pytz/reference.pyi", "stubs/pytz/pytz/tzfile.pyi", "stubs/google-cloud-ndb", + "stubs/paho-mqtt", "stubs/passlib", "stubs/peewee", "stubs/pep8-naming", diff --git a/stubs/paho-mqtt/METADATA.toml b/stubs/paho-mqtt/METADATA.toml new file mode 100644 index 000000000000..6d7acb991a43 --- /dev/null +++ b/stubs/paho-mqtt/METADATA.toml @@ -0,0 +1,4 @@ +version = "1.6.*" + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/paho-mqtt/paho/__init__.pyi b/stubs/paho-mqtt/paho/__init__.pyi new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stubs/paho-mqtt/paho/mqtt/__init__.pyi b/stubs/paho-mqtt/paho/mqtt/__init__.pyi new file mode 100644 index 000000000000..ce4f3fba0660 --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/__init__.pyi @@ -0,0 +1 @@ +class MQTTException(Exception): ... diff --git a/stubs/paho-mqtt/paho/mqtt/client.pyi b/stubs/paho-mqtt/paho/mqtt/client.pyi new file mode 100644 index 000000000000..3a1e4cc167bc --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/client.pyi @@ -0,0 +1,321 @@ +import logging +import socket as _socket +import time +import types +from collections.abc import Callable, Iterable +from typing import Any, TypeVar +from typing_extensions import TypeAlias + +from .matcher import MQTTMatcher as MQTTMatcher +from .properties import Properties as Properties +from .reasoncodes import ReasonCodes as ReasonCodes +from .subscribeoptions import SubscribeOptions as SubscribeOptions + +ssl: types.ModuleType | None +socks: types.ModuleType | None +time_func = time.monotonic +HAVE_DNS: bool +EAGAIN: int | Any +MQTTv31: int +MQTTv311: int +MQTTv5: int +unicode = str +basestring = str +CONNECT: int +CONNACK: int +PUBLISH: int +PUBACK: int +PUBREC: int +PUBREL: int +PUBCOMP: int +SUBSCRIBE: int +SUBACK: int +UNSUBSCRIBE: int +UNSUBACK: int +PINGREQ: int +PINGRESP: int +DISCONNECT: int +AUTH: int +MQTT_LOG_INFO: int +MQTT_LOG_NOTICE: int +MQTT_LOG_WARNING: int +MQTT_LOG_ERR: int +MQTT_LOG_DEBUG: int +LOGGING_LEVEL: dict[int, int] +CONNACK_ACCEPTED: int +CONNACK_REFUSED_PROTOCOL_VERSION: int +CONNACK_REFUSED_IDENTIFIER_REJECTED: int +CONNACK_REFUSED_SERVER_UNAVAILABLE: int +CONNACK_REFUSED_BAD_USERNAME_PASSWORD: int +CONNACK_REFUSED_NOT_AUTHORIZED: int +mqtt_cs_new: int +mqtt_cs_connected: int +mqtt_cs_disconnecting: int +mqtt_cs_connect_async: int +mqtt_ms_invalid: int +mqtt_ms_publish: int +mqtt_ms_wait_for_puback: int +mqtt_ms_wait_for_pubrec: int +mqtt_ms_resend_pubrel: int +mqtt_ms_wait_for_pubrel: int +mqtt_ms_resend_pubcomp: int +mqtt_ms_wait_for_pubcomp: int +mqtt_ms_send_pubrec: int +mqtt_ms_queued: int +MQTT_ERR_AGAIN: int +MQTT_ERR_SUCCESS: int +MQTT_ERR_NOMEM: int +MQTT_ERR_PROTOCOL: int +MQTT_ERR_INVAL: int +MQTT_ERR_NO_CONN: int +MQTT_ERR_CONN_REFUSED: int +MQTT_ERR_NOT_FOUND: int +MQTT_ERR_CONN_LOST: int +MQTT_ERR_TLS: int +MQTT_ERR_PAYLOAD_SIZE: int +MQTT_ERR_NOT_SUPPORTED: int +MQTT_ERR_AUTH: int +MQTT_ERR_ACL_DENIED: int +MQTT_ERR_UNKNOWN: int +MQTT_ERR_ERRNO: int +MQTT_ERR_QUEUE_SIZE: int +MQTT_ERR_KEEPALIVE: int +MQTT_CLIENT: int +MQTT_BRIDGE: int +MQTT_CLEAN_START_FIRST_ONLY: int +sockpair_data: bytes +_Payload: TypeAlias = str | bytes | bytearray | float +_ExtraHeader: TypeAlias = dict[str, str] | Callable[[dict[str, str]], dict[str, str]] +_OnLog: TypeAlias = Callable[[Client, Any, int, str], None] +_OnConnect = TypeVar( + "_OnConnect", + Callable[[Client, Any, dict[str, int], int], None], + Callable[[Client, Any, dict[str, int], ReasonCodes, Properties | None], None], +) +_OnConnectFail: TypeAlias = Callable[[Client, Any], None] +_OnSubscribe = TypeVar( + "_OnSubscribe", + Callable[[Client, Any, int, Iterable[int]], None], + Callable[[Client, Any, Iterable[ReasonCodes], Iterable[Properties]], None], +) +_OnMessage: TypeAlias = Callable[[Client, Any, MQTTMessage], None] +_OnPublish: TypeAlias = Callable[[Client, Any, int], None] +_OnUnsubscribe = TypeVar( + "_OnUnsubscribe", + Callable[[Client, Any, int], None], + Callable[[Client, Any, int, Iterable[Properties], Iterable[ReasonCodes]], None], +) +_OnDisconnect = TypeVar( + "_OnDisconnect", Callable[[Client, Any, int], None], Callable[[Client, Any, int, ReasonCodes | None, Properties | None], None] +) +_OnSocket: TypeAlias = Callable[[Client, Any, _socket.socket | Any | None], None] + +class WebsocketConnectionError(ValueError): ... + +def error_string(mqtt_errno: int) -> str: ... +def connack_string(connack_code: int) -> str: ... +def base62(num: int, base: str = ..., padding: int = ...) -> str: ... +def topic_matches_sub(sub: str, topic: str) -> bool: ... + +class MQTTMessageInfo: + mid: int + rc: int + def __init__(self, mid: int) -> None: ... + def __iter__(self) -> MQTTMessageInfo: ... + def __next__(self) -> int: ... + def next(self) -> int: ... + def __getitem__(self, index: int) -> int: ... + def wait_for_publish(self, timeout: float | None = ...) -> None: ... + def is_published(self) -> bool: ... + +class MQTTMessage: + timestamp: int + state: int + dup: bool + mid: int + payload: bytes | bytearray + qos: int + retain: bool + info: MQTTMessageInfo + properties: Properties | None + def __init__(self, mid: int = ..., topic: bytes | bytearray = ...) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + @property + def topic(self) -> str: ... + @topic.setter + def topic(self, value: bytes | bytearray) -> None: ... + +class Client: + suppress_exceptions: bool + def __init__( + self, + client_id: str = ..., + clean_session: bool | None = ..., + userdata: Any | None = ..., + protocol: int = ..., + transport: str = ..., + reconnect_on_failure: bool = ..., + ) -> None: ... + def __del__(self) -> None: ... + def reinitialise(self, client_id: str = ..., clean_session: bool = ..., userdata: Any | None = ...) -> None: ... + def ws_set_options(self, path: str = ..., headers: _ExtraHeader | None = ...) -> None: ... + def tls_set_context(self, context: Any | None = ...) -> None: ... + def tls_set( + self, + ca_certs: str | None = ..., + certfile: str | None = ..., + keyfile: str | None = ..., + cert_reqs: Any | None = ..., + tls_version: Any | None = ..., + ciphers: str | None = ..., + keyfile_password: Any | None = ..., + ) -> None: ... + def tls_insecure_set(self, value: bool) -> None: ... + def proxy_set(self, **proxy_args: str | int) -> None: ... + def enable_logger(self, logger: logging.Logger | None = ...) -> None: ... + def disable_logger(self) -> None: ... + def connect( + self, + host: str, + port: int = ..., + keepalive: int = ..., + bind_address: str = ..., + bind_port: int = ..., + clean_start: int = ..., + properties: Properties | None = ..., + ) -> int: ... + def connect_srv( + self, + domain: str | None = ..., + keepalive: int = ..., + bind_address: str = ..., + clean_start: int = ..., + properties: Properties | None = ..., + ) -> int: ... + def connect_async( + self, + host: str, + port: int = ..., + keepalive: int = ..., + bind_address: str = ..., + bind_port: int = ..., + clean_start: int = ..., + properties: Properties | None = ..., + ) -> None: ... + def reconnect_delay_set(self, min_delay: int = ..., max_delay: int = ...) -> None: ... + def reconnect(self) -> int: ... + def loop(self, timeout: float = ..., max_packets: int = ...) -> int: ... + def publish( + self, topic: str, payload: _Payload | None = ..., qos: int = ..., retain: bool = ..., properties: Properties | None = ... + ) -> MQTTMessageInfo: ... + def username_pw_set(self, username: str, password: str | bytes | bytearray | None = ...) -> None: ... + def enable_bridge_mode(self) -> None: ... + def is_connected(self) -> bool: ... + def disconnect(self, reasoncode: ReasonCodes | None = ..., properties: Properties | None = ...) -> int: ... + def subscribe( + self, + topic: str | tuple[str, SubscribeOptions] | list[tuple[str, SubscribeOptions]] | list[tuple[str, int]], + qos: int = ..., + options: SubscribeOptions | None = ..., + properties: Properties | None = ..., + ) -> tuple[int, int]: ... + def unsubscribe(self, topic: str | list[str], properties: Properties | None = ...) -> tuple[int, int]: ... + def loop_read(self, max_packets: int = ...) -> int: ... + def loop_write(self, max_packets: int = ...) -> int: ... + def want_write(self) -> bool: ... + def loop_misc(self) -> int: ... + def max_inflight_messages_set(self, inflight: int) -> None: ... + def max_queued_messages_set(self, queue_size: int) -> Client: ... + def message_retry_set(self, retry: Any) -> None: ... + def user_data_set(self, userdata: Any) -> None: ... + def will_set( + self, topic: str, payload: _Payload | None = ..., qos: int = ..., retain: bool = ..., properties: Properties | None = ... + ) -> None: ... + def will_clear(self) -> None: ... + def socket(self) -> _socket.socket | Any: ... + def loop_forever(self, timeout: float = ..., max_packets: int = ..., retry_first_connection: bool = ...) -> int: ... + def loop_start(self) -> int | None: ... + def loop_stop(self, force: bool = ...) -> int | None: ... + @property + def on_log(self) -> _OnLog | None: ... + @on_log.setter + def on_log(self, func: _OnLog) -> None: ... + def log_callback(self) -> Callable[[_OnLog], _OnLog]: ... + @property + def on_connect(self) -> _OnConnect | None: ... + @on_connect.setter + def on_connect(self, func: _OnConnect) -> None: ... + def connect_callback(self) -> Callable[[_OnConnect], _OnConnect]: ... + @property + def on_connect_fail(self) -> _OnConnectFail | None: ... + @on_connect_fail.setter + def on_connect_fail(self, func: _OnConnectFail) -> None: ... + def connect_fail_callback(self) -> Callable[[_OnConnectFail], _OnConnectFail]: ... + @property + def on_subscribe(self) -> _OnSubscribe | None: ... + @on_subscribe.setter + def on_subscribe(self, func: _OnSubscribe) -> None: ... + def subscribe_callback(self) -> Callable[[_OnSubscribe], _OnSubscribe]: ... + @property + def on_message(self) -> _OnMessage | None: ... + @on_message.setter + def on_message(self, func: _OnMessage) -> 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 publish_callback(self) -> Callable[[_OnPublish], _OnPublish]: ... + @property + def on_unsubscribe(self) -> _OnUnsubscribe | None: ... + @on_unsubscribe.setter + def on_unsubscribe(self, func: _OnUnsubscribe) -> None: ... + def unsubscribe_callback(self) -> Callable[[_OnUnsubscribe], _OnUnsubscribe]: ... + @property + def on_disconnect(self) -> _OnDisconnect: ... + @on_disconnect.setter + def on_disconnect(self, func: _OnDisconnect) -> None: ... + def disconnect_callback(self) -> Callable[[_OnDisconnect], _OnDisconnect]: ... + @property + def on_socket_open(self) -> _OnSocket: ... + @on_socket_open.setter + def on_socket_open(self, func: _OnSocket) -> None: ... + def socket_open_callback(self) -> Callable[[_OnSocket], _OnSocket]: ... + @property + def on_socket_close(self) -> _OnSocket: ... + @on_socket_close.setter + def on_socket_close(self, func: _OnSocket) -> None: ... + def socket_close_callback(self) -> Callable[[_OnSocket], _OnSocket]: ... + @property + def on_socket_register_write(self) -> _OnSocket: ... + @on_socket_register_write.setter + def on_socket_register_write(self, func: _OnSocket) -> None: ... + def socket_register_write_callback(self) -> Callable[[_OnSocket], _OnSocket]: ... + @property + def on_socket_unregister_write(self) -> _OnSocket: ... + @on_socket_unregister_write.setter + def on_socket_unregister_write(self, func: _OnSocket) -> 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]: ... + def message_callback_remove(self, sub: str) -> None: ... + +class WebsocketWrapper: + OPCODE_CONTINUATION: int + OPCODE_TEXT: int + OPCODE_BINARY: int + OPCODE_CONNCLOSE: int + OPCODE_PING: int + OPCODE_PONG: int + connected: bool + def __init__(self, socket: Any, host: str, port: int, is_ssl: bool, path: str, extra_headers: _ExtraHeader) -> None: ... + def __del__(self) -> None: ... + def recv(self, length: int) -> bytes | bytearray | None: ... + def read(self, length: int) -> bytes | bytearray | None: ... + def send(self, data: bytes | bytearray) -> int: ... + def write(self, data: bytes | bytearray) -> int: ... + def close(self) -> None: ... + def fileno(self) -> int: ... + def pending(self) -> int: ... + def setblocking(self, flag: bool) -> None: ... diff --git a/stubs/paho-mqtt/paho/mqtt/matcher.pyi b/stubs/paho-mqtt/paho/mqtt/matcher.pyi new file mode 100644 index 000000000000..549ac1b36ab7 --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/matcher.pyi @@ -0,0 +1,11 @@ +from collections.abc import Generator +from typing import Any + +class MQTTMatcher: + class Node: ... + + def __init__(self) -> None: ... + def __setitem__(self, key: str, value: Any) -> None: ... + def __getitem__(self, key: str) -> Any: ... + def __delitem__(self, key: str) -> None: ... + def iter_match(self, topic: str) -> Generator[Any, None, None]: ... diff --git a/stubs/paho-mqtt/paho/mqtt/packettypes.pyi b/stubs/paho-mqtt/paho/mqtt/packettypes.pyi new file mode 100644 index 000000000000..2fe5644e58d7 --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/packettypes.pyi @@ -0,0 +1,19 @@ +class PacketTypes: + indexes: range + CONNECT: int + CONNACK: int + PUBLISH: int + PUBACK: int + PUBREC: int + PUBREL: int + PUBCOMP: int + SUBSCRIBE: int + SUBACK: int + UNSUBSCRIBE: int + UNSUBACK: int + PINGREQ: int + PINGRESP: int + DISCONNECT: int + AUTH: int + WILLMESSAGE: int + Names: list[str] diff --git a/stubs/paho-mqtt/paho/mqtt/properties.pyi b/stubs/paho-mqtt/paho/mqtt/properties.pyi new file mode 100644 index 000000000000..174a6a0e54bc --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/properties.pyi @@ -0,0 +1,38 @@ +from typing import Any + +from . import MQTTException as MQTTException + +class MalformedPacket(MQTTException): ... + +def writeInt16(length: int) -> bytearray: ... +def readInt16(buf: bytes) -> int: ... +def writeInt32(length: int) -> bytearray: ... +def readInt32(buf: bytes) -> int: ... +def writeUTF(data: str | bytes) -> bytearray: ... +def readUTF(buffer: bytes, maxlen: int) -> tuple[str, int]: ... +def writeBytes(buffer: bytes) -> bytearray: ... +def readBytes(buffer: bytes) -> tuple[bytes, int]: ... + +class VariableByteIntegers: + @staticmethod + def encode(x: int) -> bytes: ... + @staticmethod + def decode(buffer: bytes) -> tuple[int, int]: ... + +class Properties: + packetType: int + types: list[str] + names: dict[str, int] + properties: dict[int, tuple[int, list[int]]] + def __init__(self, packetType: int) -> None: ... + def allowsMultiple(self, compressedName: str) -> bool: ... + def getIdentFromName(self, compressedName: str) -> int: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def json(self) -> dict[str, Any]: ... + def isEmpty(self) -> bool: ... + def clear(self) -> None: ... + def writeProperty(self, identifier: int, type: int, value: Any) -> bytes: ... + def pack(self) -> bytes: ... + def readProperty(self, buffer: bytes, type: int, propslen: int) -> Any: ... + def getNameFromIdent(self, identifier: int) -> str | None: ... + def unpack(self, buffer: bytes) -> tuple[Properties, int]: ... diff --git a/stubs/paho-mqtt/paho/mqtt/publish.pyi b/stubs/paho-mqtt/paho/mqtt/publish.pyi new file mode 100644 index 000000000000..b23fb63ebeaa --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/publish.pyi @@ -0,0 +1,59 @@ +from collections.abc import Iterable +from typing_extensions import NotRequired, TypeAlias, TypedDict + +_Payload: TypeAlias = str | bytes | bytearray | float + +class _Msg(TypedDict): + topic: str + payload: NotRequired[_Payload | None] + qos: NotRequired[int] + retain: NotRequired[int] + +class _Auth(TypedDict): + username: str + password: NotRequired[str] + +class _TLS(TypedDict): + ca_certs: str + certfile: NotRequired[str] + keyfile: NotRequired[str] + tls_version: NotRequired[str] + ciphers: NotRequired[str] + insecure: NotRequired[str] + +class _Proxy(TypedDict): + proxy_type: int + proxy_addr: str + proxy_rdns: NotRequired[str] + proxy_username: NotRequired[str] + proxy_passwor: NotRequired[str] + +def multiple( + msgs: Iterable[_Msg], + hostname: str = ..., + port: int = ..., + client_id: str = ..., + keepalive: int = ..., + will: _Msg | None = ..., + auth: _Auth | None = ..., + tls: _TLS | None = ..., + protocol: int = ..., + transport: str = ..., + proxy_args: _Proxy | None = ..., +) -> None: ... +def single( + topic: str, + payload: _Payload | None = ..., + qos: int | None = ..., + retain: bool | None = ..., + hostname: str = ..., + port: int = ..., + client_id: str = ..., + keepalive: int = ..., + will: _Msg | None = ..., + auth: _Auth | None = ..., + tls: _TLS | None = ..., + protocol: int = ..., + transport: str = ..., + proxy_args: _Proxy | None = ..., +) -> None: ... diff --git a/stubs/paho-mqtt/paho/mqtt/reasoncodes.pyi b/stubs/paho-mqtt/paho/mqtt/reasoncodes.pyi new file mode 100644 index 000000000000..3a3b20f5beb2 --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/reasoncodes.pyi @@ -0,0 +1,13 @@ +class ReasonCodes: + packetType: int + names: dict[int, dict[str, list[int]]] + value: int + def __init__(self, packetType: int, aName: str = ..., identifier: int = ...) -> None: ... + def __getName__(self, packetType: int, identifier: int) -> str: ... + def getId(self, name: str) -> int: ... + def set(self, name: str) -> None: ... + def unpack(self, buffer: bytearray) -> int: ... + def getName(self) -> str: ... + def __eq__(self, other: object) -> bool: ... + def json(self) -> str: ... + def pack(self) -> bytearray: ... diff --git a/stubs/paho-mqtt/paho/mqtt/subscribe.pyi b/stubs/paho-mqtt/paho/mqtt/subscribe.pyi new file mode 100644 index 000000000000..9870e5d00ce1 --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/subscribe.pyi @@ -0,0 +1,40 @@ +from collections.abc import Callable +from typing import Any + +from .client import Client, MQTTMessage +from .publish import _TLS, _Auth, _Msg, _Proxy + +def callback( + callback: Callable[[Client, Any, MQTTMessage], None], + topics: list[str], + qos: int = ..., + userdata: Any | None = ..., + hostname: str = ..., + port: int = ..., + client_id: str = ..., + keepalive: int = ..., + will: _Msg | None = ..., + auth: _Auth | None = ..., + tls: _TLS | None = ..., + protocol: int = ..., + transport: str = ..., + clean_session: bool = ..., + proxy_args: _Proxy | None = ..., +) -> None: ... +def simple( + topics: list[str], + qos: int = ..., + msg_count: int = ..., + retained: bool = ..., + hostname: str = ..., + port: int = ..., + client_id: str = ..., + keepalive: int = ..., + will: _Msg | None = ..., + auth: _Auth | None = ..., + tls: _TLS | None = ..., + protocol: int = ..., + transport: str = ..., + clean_session: bool = ..., + proxy_args: _Proxy | None = ..., +) -> list[MQTTMessage] | MQTTMessage: ... diff --git a/stubs/paho-mqtt/paho/mqtt/subscribeoptions.pyi b/stubs/paho-mqtt/paho/mqtt/subscribeoptions.pyi new file mode 100644 index 000000000000..4d9c58501a30 --- /dev/null +++ b/stubs/paho-mqtt/paho/mqtt/subscribeoptions.pyi @@ -0,0 +1,25 @@ +from typing import Any +from typing_extensions import TypedDict + +from . import MQTTException as MQTTException + +class _SubscribeOptionsJson(TypedDict): + QoS: int + noLocal: bool + retainAsPublished: bool + retainHandling: int + +class SubscribeOptions: + RETAIN_SEND_ON_SUBSCRIBE: int + RETAIN_SEND_IF_NEW_SUB: int + RETAIN_DO_NOT_SEND: int + names: list[str] + Qos: int + noLocal: bool + retainAsPublished: bool + retainHandling: int + def __init__(self, qos: int = ..., noLocal: bool = ..., retainAsPublished: bool = ..., retainHandling: int = ...) -> None: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def pack(self) -> bytes: ... + def unpack(self, buffer: bytes | bytearray) -> int: ... + def json(self) -> _SubscribeOptionsJson: ... From ef8fd318e9e63be051be5ccc4adc7b8b441e2107 Mon Sep 17 00:00:00 2001 From: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com> Date: Thu, 6 Oct 2022 10:15:25 +0200 Subject: [PATCH 2/3] Fix typing of subscribe.simple(topics) --- stubs/paho-mqtt/paho/mqtt/subscribe.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/paho-mqtt/paho/mqtt/subscribe.pyi b/stubs/paho-mqtt/paho/mqtt/subscribe.pyi index 9870e5d00ce1..e04655771597 100644 --- a/stubs/paho-mqtt/paho/mqtt/subscribe.pyi +++ b/stubs/paho-mqtt/paho/mqtt/subscribe.pyi @@ -22,7 +22,7 @@ def callback( proxy_args: _Proxy | None = ..., ) -> None: ... def simple( - topics: list[str], + topics: str | list[str], qos: int = ..., msg_count: int = ..., retained: bool = ..., From 128e0d4b48944b71f584747c2fffcf5ae1664d6a Mon Sep 17 00:00:00 2001 From: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com> Date: Thu, 6 Oct 2022 16:52:51 +0200 Subject: [PATCH 3/3] Add _UserData, improve sockets and ssl typing --- stubs/paho-mqtt/paho/mqtt/client.pyi | 49 ++++++++++++++----------- stubs/paho-mqtt/paho/mqtt/subscribe.pyi | 7 ++-- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/stubs/paho-mqtt/paho/mqtt/client.pyi b/stubs/paho-mqtt/paho/mqtt/client.pyi index 3a1e4cc167bc..306b43a33564 100644 --- a/stubs/paho-mqtt/paho/mqtt/client.pyi +++ b/stubs/paho-mqtt/paho/mqtt/client.pyi @@ -1,5 +1,6 @@ import logging import socket as _socket +import ssl as _ssl import time import types from collections.abc import Callable, Iterable @@ -84,31 +85,35 @@ MQTT_CLIENT: int MQTT_BRIDGE: int MQTT_CLEAN_START_FIRST_ONLY: int sockpair_data: bytes +_UserData: TypeAlias = Any +_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, Any, int, str], None] +_OnLog: TypeAlias = Callable[[Client, _UserData, int, str], object] _OnConnect = TypeVar( "_OnConnect", - Callable[[Client, Any, dict[str, int], int], None], - Callable[[Client, Any, dict[str, int], ReasonCodes, Properties | None], None], + Callable[[Client, _UserData, dict[str, int], int], object], + Callable[[Client, _UserData, dict[str, int], ReasonCodes, Properties | None], object], ) -_OnConnectFail: TypeAlias = Callable[[Client, Any], None] +_OnConnectFail: TypeAlias = Callable[[Client, _UserData], object] _OnSubscribe = TypeVar( "_OnSubscribe", - Callable[[Client, Any, int, Iterable[int]], None], - Callable[[Client, Any, Iterable[ReasonCodes], Iterable[Properties]], None], + Callable[[Client, _UserData, int, Iterable[int]], object], + Callable[[Client, _UserData, Iterable[ReasonCodes], Iterable[Properties]], object], ) -_OnMessage: TypeAlias = Callable[[Client, Any, MQTTMessage], None] -_OnPublish: TypeAlias = Callable[[Client, Any, int], None] +_OnMessage: TypeAlias = Callable[[Client, _UserData, MQTTMessage], object] +_OnPublish: TypeAlias = Callable[[Client, _UserData, int], object] _OnUnsubscribe = TypeVar( "_OnUnsubscribe", - Callable[[Client, Any, int], None], - Callable[[Client, Any, int, Iterable[Properties], Iterable[ReasonCodes]], None], + Callable[[Client, _UserData, int], object], + Callable[[Client, _UserData, int, Iterable[Properties], Iterable[ReasonCodes]], object], ) _OnDisconnect = TypeVar( - "_OnDisconnect", Callable[[Client, Any, int], None], Callable[[Client, Any, int, ReasonCodes | None, Properties | None], None] + "_OnDisconnect", + Callable[[Client, _UserData, int], object], + Callable[[Client, _UserData, int, ReasonCodes | None, Properties | None], object], ) -_OnSocket: TypeAlias = Callable[[Client, Any, _socket.socket | Any | None], None] +_OnSocket: TypeAlias = Callable[[Client, _UserData, _Socket | WebsocketWrapper | None], object] class WebsocketConnectionError(ValueError): ... @@ -152,24 +157,24 @@ class Client: self, client_id: str = ..., clean_session: bool | None = ..., - userdata: Any | None = ..., + userdata: _UserData | None = ..., protocol: int = ..., transport: str = ..., reconnect_on_failure: bool = ..., ) -> None: ... def __del__(self) -> None: ... - def reinitialise(self, client_id: str = ..., clean_session: bool = ..., userdata: Any | None = ...) -> None: ... + def reinitialise(self, client_id: str = ..., clean_session: bool = ..., userdata: _UserData | None = ...) -> None: ... def ws_set_options(self, path: str = ..., headers: _ExtraHeader | None = ...) -> None: ... - def tls_set_context(self, context: Any | None = ...) -> None: ... + def tls_set_context(self, context: _ssl.SSLContext | None = ...) -> None: ... def tls_set( self, ca_certs: str | None = ..., certfile: str | None = ..., keyfile: str | None = ..., - cert_reqs: Any | None = ..., - tls_version: Any | None = ..., + cert_reqs: _ssl.VerifyMode | None = ..., + tls_version: _ssl._SSLMethod | None = ..., ciphers: str | None = ..., - keyfile_password: Any | None = ..., + keyfile_password: _ssl._PasswordType | None = ..., ) -> None: ... def tls_insecure_set(self, value: bool) -> None: ... def proxy_set(self, **proxy_args: str | int) -> None: ... @@ -227,13 +232,13 @@ class Client: def loop_misc(self) -> int: ... def max_inflight_messages_set(self, inflight: int) -> None: ... def max_queued_messages_set(self, queue_size: int) -> Client: ... - def message_retry_set(self, retry: Any) -> None: ... - def user_data_set(self, userdata: Any) -> None: ... + def message_retry_set(self, retry: object) -> None: ... + def user_data_set(self, userdata: _UserData) -> None: ... def will_set( self, topic: str, payload: _Payload | None = ..., qos: int = ..., retain: bool = ..., properties: Properties | None = ... ) -> None: ... def will_clear(self) -> None: ... - def socket(self) -> _socket.socket | Any: ... + def socket(self) -> _Socket | WebsocketWrapper: ... def loop_forever(self, timeout: float = ..., max_packets: int = ..., retry_first_connection: bool = ...) -> int: ... def loop_start(self) -> int | None: ... def loop_stop(self, force: bool = ...) -> int | None: ... @@ -309,7 +314,7 @@ class WebsocketWrapper: OPCODE_PING: int OPCODE_PONG: int connected: bool - def __init__(self, socket: Any, 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: ... def __del__(self) -> None: ... def recv(self, length: int) -> bytes | bytearray | None: ... def read(self, length: int) -> bytes | bytearray | None: ... diff --git a/stubs/paho-mqtt/paho/mqtt/subscribe.pyi b/stubs/paho-mqtt/paho/mqtt/subscribe.pyi index e04655771597..a9a7e0058a78 100644 --- a/stubs/paho-mqtt/paho/mqtt/subscribe.pyi +++ b/stubs/paho-mqtt/paho/mqtt/subscribe.pyi @@ -1,14 +1,13 @@ from collections.abc import Callable -from typing import Any -from .client import Client, MQTTMessage +from .client import Client, MQTTMessage, _UserData from .publish import _TLS, _Auth, _Msg, _Proxy def callback( - callback: Callable[[Client, Any, MQTTMessage], None], + callback: Callable[[Client, _UserData, MQTTMessage], None], topics: list[str], qos: int = ..., - userdata: Any | None = ..., + userdata: _UserData | None = ..., hostname: str = ..., port: int = ..., client_id: str = ...,