Skip to content

Commit 47c0547

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 esphome#1678 (PTH) and esphome#1679 (PT006/PT007) and esphome#1683 (B) -- one ruff family at a time.
1 parent dc32bd4 commit 47c0547

10 files changed

Lines changed: 11 additions & 10 deletions

File tree

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
@@ -17,6 +17,7 @@ select = [
1717
"G", # flake8-logging-format
1818
"I", # isort
1919
"PERF", # Perflint
20+
"PGH", # pygrep-hooks
2021
"PIE", # flake8-pie
2122
"PL", # pylint
2223
"PT006", # pytest-parametrize-names-wrong-type

tests/test_log_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from aioesphomeapi.api_pb2 import (
1313
DisconnectRequest,
1414
DisconnectResponse,
15-
SubscribeLogsResponse, # type: ignore
15+
SubscribeLogsResponse, # type: ignore[attr-defined]
1616
)
1717
from aioesphomeapi.client import APIClient
1818
from aioesphomeapi.connection import APIConnection

0 commit comments

Comments
 (0)