Skip to content

Commit 7a65ec8

Browse files
committed
Enable ruff PGH and replace blanket noqa/type ignore directives
Adds PGH (pygrep-hooks) to the ruff rule selection so blanket `# type: ignore` and `# flake8: noqa` directives are flagged. All 12 existing violations are converted to specific codes: - 10 `# type: ignore` -> `# type: ignore[attr-defined]` on `from .api_pb2 import (...)` blocks (protobuf-generated module lacks stubs for its dynamically-emitted symbols). - 1 `# type: ignore` -> `# type: ignore[union-attr]` on the HomeassistantServiceMap iteration in `_convert_homeassistant_service_map` (mypy widens the iter element to `str | Any` after the dict isinstance branch). - `# flake8: noqa` on `aioesphomeapi/__init__.py` -> `# ruff: noqa: F401, F403` (file is the public re-export surface; F401 covers the unused-name warnings on each re-export and F403 covers the `from .model import *`). Follows the cadence of #1678 (PTH) and #1679 (PT006/PT007) and #1683 (B) -- one ruff family at a time.
1 parent f544437 commit 7a65ec8

11 files changed

Lines changed: 17 additions & 16 deletions

File tree

aioesphomeapi/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# flake8: noqa
2-
from .api_pb2 import ( # type: ignore[attr-defined] # noqa: F401
1+
# ruff: noqa: F401, F403
2+
from .api_pb2 import ( # type: ignore[attr-defined]
33
BluetoothLERawAdvertisement,
44
BluetoothLERawAdvertisementsResponse,
55
)
@@ -10,20 +10,20 @@
1010
ESPHOME_GATT_ERRORS,
1111
MESSAGE_TYPE_TO_PROTO,
1212
APIConnectionError,
13-
EncryptionPlaintextAPIError,
13+
BadMACAddressAPIError,
1414
BadNameAPIError,
1515
BluetoothConnectionDroppedError,
16+
EncryptionHelloAPIError,
17+
EncryptionPlaintextAPIError,
1618
HandshakeAPIError,
1719
InvalidAuthAPIError,
1820
InvalidEncryptionKeyAPIError,
1921
ProtocolAPIError,
2022
RequiresEncryptionAPIError,
2123
ResolveAPIError,
22-
EncryptionHelloAPIError,
2324
SocketAPIError,
24-
BadMACAddressAPIError,
2525
wifi_mac_to_bluetooth_mac,
2626
)
27+
from .log_parser import LogParser, parse_log_message
2728
from .model import *
2829
from .reconnect_logic import ReconnectLogic
29-
from .log_parser import parse_log_message, LogParser

aioesphomeapi/client.py

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

1010
from google.protobuf import message
1111

12-
from .api_pb2 import ( # type: ignore
12+
from .api_pb2 import ( # type: ignore[attr-defined]
1313
AlarmControlPanelCommandRequest,
1414
BluetoothConnectionsFreeResponse,
1515
BluetoothDeviceClearCacheResponse,

aioesphomeapi/client_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from ._frame_helper.noise import APINoiseFrameHelper # noqa: F401
1818
from ._frame_helper.plain_text import APIPlaintextFrameHelper # noqa: F401
19-
from .api_pb2 import ( # type: ignore
19+
from .api_pb2 import ( # type: ignore[attr-defined]
2020
BluetoothConnectionsFreeResponse,
2121
BluetoothDeviceConnectionResponse,
2222
BluetoothGATTErrorResponse,

aioesphomeapi/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ._frame_helper.base import MAX_NAME_LEN, safe_label_str
2323
from ._frame_helper.noise import APINoiseFrameHelper
2424
from ._frame_helper.plain_text import APIPlaintextFrameHelper
25-
from .api_pb2 import ( # type: ignore # type: ignore
25+
from .api_pb2 import ( # type: ignore[attr-defined]
2626
DST_RULE_TYPE_DAY_OF_YEAR as DST_RULE_TYPE_DAY_OF_YEAR_PB,
2727
DST_RULE_TYPE_JULIAN_NO_LEAP as DST_RULE_TYPE_JULIAN_NO_LEAP_PB,
2828
DST_RULE_TYPE_MONTH_WEEK_DAY as DST_RULE_TYPE_MONTH_WEEK_DAY_PB,

aioesphomeapi/core.py

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

66
from aioesphomeapi.model import BluetoothGATTError
77

8-
from .api_pb2 import ( # type: ignore
8+
from .api_pb2 import ( # type: ignore[attr-defined]
99
AlarmControlPanelCommandRequest,
1010
AlarmControlPanelStateResponse,
1111
AuthenticationRequest,

aioesphomeapi/log_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
import sys
1010

11-
from .api_pb2 import SubscribeLogsResponse # type: ignore
11+
from .api_pb2 import SubscribeLogsResponse # type: ignore[attr-defined]
1212
from .client import APIClient
1313
from .log_parser import parse_log_message
1414
from .log_runner import async_run

aioesphomeapi/log_runner.py

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

77
from zeroconf.asyncio import AsyncZeroconf
88

9-
from .api_pb2 import SubscribeLogsResponse # type: ignore
9+
from .api_pb2 import SubscribeLogsResponse # type: ignore[attr-defined]
1010
from .client import APIClient
1111
from .core import APIConnectionError
1212
from .model import EntityInfo, EntityState, LogLevel

aioesphomeapi/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
if TYPE_CHECKING:
20-
from .api_pb2 import ( # type: ignore
20+
from .api_pb2 import ( # type: ignore[attr-defined]
2121
BluetoothLEAdvertisementResponse,
2222
HomeassistantServiceMap,
2323
)
@@ -1398,7 +1398,7 @@ def _convert_homeassistant_service_map(
13981398
if isinstance(value, dict):
13991399
# already a dict, don't convert
14001400
return value
1401-
return {v.key: v.value for v in value} # type: ignore
1401+
return {v.key: v.value for v in value} # type: ignore[union-attr]
14021402

14031403

14041404
@_frozen_dataclass_decorator

aioesphomeapi/model_conversions.py

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

33
from typing import Any
44

5-
from .api_pb2 import ( # type: ignore
5+
from .api_pb2 import ( # type: ignore[attr-defined]
66
AlarmControlPanelStateResponse,
77
BinarySensorStateResponse,
88
ClimateStateResponse,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ select = [
1616
"G", # flake8-logging-format
1717
"I", # isort
1818
"PERF", # Perflint
19+
"PGH", # pygrep-hooks
1920
"PIE", # flake8-pie
2021
"PL", # pylint
2122
"PT006", # pytest-parametrize-names-wrong-type

0 commit comments

Comments
 (0)