diff --git a/pyproject.toml b/pyproject.toml index 57e462a1..2b62fb8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,14 +95,19 @@ testpaths = "tests src" exclude = ["test/lib/python/*"] extend-select = [ "B", + "C4", + "E", "E9", "F63", "F7", "F82", "FLY", # flynt "I", + "ISC", + "PERF", "S", # Bandit "UP", + "RUF", "W", ] ignore = [] @@ -118,11 +123,13 @@ line-length = 167 "F811", "F841", "I", + "PERF", "S", "UP", ] "tests/**/*.py" = [ "F811", + "PERF203", "S101", "S105", "S106", diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index e5a0811d..024f80ab 100644 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -3516,9 +3516,10 @@ def _handle_suback(self) -> None: if self._protocol == MQTTv5: properties = Properties(SUBACK >> 4) props, props_len = properties.unpack(packet) - reasoncodes = [] - for c in packet[props_len:]: - reasoncodes.append(ReasonCodes(SUBACK >> 4, identifier=c)) + reasoncodes = [ + ReasonCodes(SUBACK >> 4, identifier=c) + for c in packet[props_len:] + ] else: pack_format = f"!{'B' * len(packet)}" granted_qos = struct.unpack(pack_format, packet) @@ -3735,9 +3736,10 @@ def _handle_unsuback(self) -> MQTTErrorCode: packet = self._in_packet['packet'][2:] properties = Properties(UNSUBACK >> 4) props, props_len = properties.unpack(packet) - reasoncodes_list = [] - for c in packet[props_len:]: - reasoncodes_list.append(ReasonCodes(UNSUBACK >> 4, identifier=c)) + reasoncodes_list = [ + ReasonCodes(UNSUBACK >> 4, identifier=c) + for c in packet[props_len:] + ] reasoncodes: ReasonCodes | list[ReasonCodes] = reasoncodes_list if len(reasoncodes_list) == 1: @@ -3849,8 +3851,7 @@ def _handle_on_message(self, message: MQTTMessage) -> None: on_message_callbacks = [] with self._callback_mutex: if topic is not None: - for callback in self._on_message_filtered.iter_match(message.topic): - on_message_callbacks.append(callback) + on_message_callbacks = list(self._on_message_filtered.iter_match(message.topic)) if len(on_message_callbacks) == 0: on_message = self.on_message @@ -3923,7 +3924,7 @@ def _reconnect_wait(self) -> None: def _proxy_is_valid(p) -> bool: # type: ignore[no-untyped-def] def check(t, a) -> bool: # type: ignore[no-untyped-def] return (socks is not None and - t in set([socks.HTTP, socks.SOCKS4, socks.SOCKS5]) and a) + t in {socks.HTTP, socks.SOCKS4, socks.SOCKS5} and a) if isinstance(p, dict): return check(p.get("proxy_type"), p.get("proxy_addr")) diff --git a/src/paho/mqtt/packettypes.py b/src/paho/mqtt/packettypes.py index 8a7f9ca9..d2051490 100644 --- a/src/paho/mqtt/packettypes.py +++ b/src/paho/mqtt/packettypes.py @@ -37,7 +37,7 @@ class PacketTypes: # Dummy packet type for properties use - will delay only applies to will WILLMESSAGE = 99 - Names = [ "reserved", \ + Names = ( "reserved", \ "Connect", "Connack", "Publish", "Puback", "Pubrec", "Pubrel", \ "Pubcomp", "Subscribe", "Suback", "Unsubscribe", "Unsuback", \ - "Pingreq", "Pingresp", "Disconnect", "Auth"] + "Pingreq", "Pingresp", "Disconnect", "Auth") diff --git a/tests/paho_test.py b/tests/paho_test.py index 9274fed6..60702c63 100644 --- a/tests/paho_test.py +++ b/tests/paho_test.py @@ -101,7 +101,22 @@ def packet_matches(name, recvd, expected): return True -def gen_connect(client_id, clean_session=True, keepalive=60, username=None, password=None, will_topic=None, will_qos=0, will_retain=False, will_payload=b"", proto_ver=4, connect_reserved=False, properties=b"", will_properties=b"", session_expiry=-1): +def gen_connect( + client_id, + clean_session=True, + keepalive=60, + username=None, + password=None, + will_topic=None, + will_qos=0, + will_retain=False, + will_payload=b"", + proto_ver=4, + connect_reserved=False, + properties=b"", + will_properties=b"", + session_expiry=-1, +): if (proto_ver&0x7F) == 3 or proto_ver == 0: remaining_length = 12 elif (proto_ver&0x7F) == 4 or proto_ver == 5: diff --git a/tests/test_mqttv5.py b/tests/test_mqttv5.py index 1be94aa8..a09800e3 100644 --- a/tests/test_mqttv5.py +++ b/tests/test_mqttv5.py @@ -930,7 +930,7 @@ def test_subscription_identifiers(self): self.waitfor(lbcallback.messages, 1, 3) self.assertEqual(len(lbcallback.messages), 1, lbcallback.messages) - expected_subsids = set([2, 3]) + expected_subsids = {2, 3} received_subsids = set( lbcallback.messages[0]["message"].properties.SubscriptionIdentifier) self.assertEqual(received_subsids, expected_subsids, received_subsids)