Skip to content

Commit

Permalink
Enable some additional linters
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreF committed Jan 14, 2024
1 parent ec1a834 commit 2c73adb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -118,11 +123,13 @@ line-length = 167
"F811",
"F841",
"I",
"PERF",
"S",
"UP",
]
"tests/**/*.py" = [
"F811",
"PERF203",
"S101",
"S105",
"S106",
Expand Down
19 changes: 10 additions & 9 deletions src/paho/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions src/paho/mqtt/packettypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
17 changes: 16 additions & 1 deletion tests/paho_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mqttv5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c73adb

Please sign in to comment.