Skip to content

Commit 11fb7ee

Browse files
authored
Enable ruff B (bugbear) and fix violations (esphome#1683)
1 parent f544437 commit 11fb7ee

9 files changed

Lines changed: 11 additions & 10 deletions

File tree

aioesphomeapi/_frame_helper/noise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ def _decode_noise_psk(self) -> bytes:
256256
server_mac = self._server_mac
257257
try:
258258
psk_bytes = binascii.a2b_base64(psk)
259-
except ValueError:
259+
except ValueError as err:
260260
raise InvalidEncryptionKeyAPIError(
261261
f"{self._log_name}: Malformed PSK (length={len(psk)}), "
262262
"expected base64-encoded 32-byte value",
263263
server_name,
264264
server_mac,
265-
)
265+
) from err
266266
if len(psk_bytes) != 32:
267267
raise InvalidEncryptionKeyAPIError(
268268
f"{self._log_name}: Malformed PSK (length={len(psk)}), "

aioesphomeapi/host_resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async def _async_resolve_host_getaddrinfo(host: str, port: int) -> list[AddrInfo
138138
)
139139
except OSError as err:
140140
_LOGGER.debug("Failed to resolve %s via getaddrinfo: %s", host, err)
141-
raise ResolveAPIError(f"Error resolving {host} to IP address: {err}")
141+
raise ResolveAPIError(f"Error resolving {host} to IP address: {err}") from err
142142

143143
_LOGGER.debug("Successfully resolved %s via getaddrinfo", host)
144144

bench/raw_ble_plain_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
b"00002f6f72672f626c75657a2f686369302f6465"
2424
),
2525
)
26-
for i in range(5):
26+
for _ in range(5):
2727
adv.advertisements.append(fake_adv)
2828

2929
type_ = 93

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exclude = [
99
[tool.ruff.lint]
1010
select = [
1111
"ASYNC", # async rules
12+
"B", # flake8-bugbear
1213
"E", # pycodestyle
1314
"F", # pyflakes/autoflake
1415
"FLY", # flynt

tests/benchmarks/test_bluetooth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def test_raw_ble_plain_text(benchmark: BenchmarkFixture) -> None:
6969
b"00002f6f72672f626c75657a2f686369302f6465"
7070
),
7171
)
72-
for i in range(5):
72+
for _ in range(5):
7373
adv.advertisements.append(fake_adv)
7474

7575
type_ = 93

tests/test__frame_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ async def test_plaintext_frame_helper_multiple_payloads_single_packet(
155155
# Make sure we correctly handle multiple payloads in a single packet
156156
mock_data_received(helper, in_bytes * 5)
157157

158-
for i in range(5):
158+
for _ in range(5):
159159
pkt = packets.pop()
160160
type_, data = pkt
161161

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def test_order_and_no_missing_numbers_in_message_type_to_proto():
99
"""Test that MESSAGE_TYPE_TO_PROTO has no missing numbers."""
10-
for idx, (k, v) in enumerate(MESSAGE_TYPE_TO_PROTO.items()):
10+
for idx, k in enumerate(MESSAGE_TYPE_TO_PROTO):
1111
assert idx + 1 == k
1212

1313

tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ async def test_bluetooth_gatt_services_from_dict() -> None:
837837
)
838838
],
839839
)
840-
services == BluetoothGATTServicesModel.from_dict(
840+
services = BluetoothGATTServicesModel.from_dict(
841841
{
842842
"services": [
843843
{

tests/test_reconnect_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ async def resolve_host_waiting_for_zeroconf(*args, **kwargs):
460460
# This simulates the resolver waiting for mDNS records
461461
try:
462462
await asyncio.wait_for(resolve_event.wait(), timeout=0.1)
463-
except TimeoutError:
464-
raise APIConnectionError("Resolution timed out")
463+
except TimeoutError as err:
464+
raise APIConnectionError("Resolution timed out") from err
465465
else:
466466
return # Resolution succeeded
467467

0 commit comments

Comments
 (0)