Skip to content

Enable ruff PGH (pygrep-hooks) rules#1684

Merged
bdraco merged 1 commit into
esphome:mainfrom
bluetoothbot:koan/ruff-pgh
May 20, 2026
Merged

Enable ruff PGH (pygrep-hooks) rules#1684
bdraco merged 1 commit into
esphome:mainfrom
bluetoothbot:koan/ruff-pgh

Conversation

@bluetoothbot
Copy link
Copy Markdown
Contributor

@bluetoothbot bluetoothbot commented May 20, 2026

What

Adds PGH (pygrep-hooks) to the ruff rule selection and converts the
12 existing violations to specific error codes.

Why

PGH003 and PGH004 flag blanket # type: ignore and # flake8: noqa
directives. Without specific codes they silence every mypy / flake8
diagnostic on the line, which can hide unrelated regressions
(e.g. a name typo on the same import line). One ruff family at a time,
following the cadence of #1678 (PTH), #1679 (PT006/PT007), and #1683 (B).

How

  • 10 × # type: ignore# type: ignore[attr-defined] on
    from .api_pb2 import … blocks — the generated protobuf module
    doesn't ship stubs, so its dynamic symbols are unresolved attributes.
  • 1 × # type: ignore# type: ignore[union-attr] on
    _convert_homeassistant_service_map, where mypy widens the iter
    element to str | Any after the isinstance(value, dict) branch.
  • aioesphomeapi/__init__.py: # flake8: noqa# ruff: noqa: F401, F403
    (covers re-export F401 and the from .model import * F403).
    The accompanying isort reorder is ruff --fix's output once the
    per-line # noqa: F401 was no longer needed.

Testing

  • ruff check . and ruff format --check . clean.
  • pytest -q — 1066 passed, 2 skipped, no regressions.

Quality Report

Changes: 11 files changed, 17 insertions(+), 16 deletions(-)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 20, 2026

Merging this PR will not alter performance

✅ 40 untouched benchmarks


Comparing bluetoothbot:koan/ruff-pgh (47c0547) with main (dc32bd4)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (dc32bd4) to head (47c0547).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1684   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         4152      4152           
=========================================
  Hits          4152      4152           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 20, 2026

@bluetoothbot rr

@bluetoothbot
Copy link
Copy Markdown
Contributor Author

PR Review — Enable ruff PGH (pygrep-hooks) rules

Mechanical ruff PGH enablement: 10 protobuf import sites get the correct narrow [attr-defined] code, the model.py service-map case correctly uses [union-attr] (mypy keeps str | Any after the isinstance branch), and the __init__.py blanket # flake8: noqa becomes # ruff: noqa: F401, F403 which covers both the re-exports and the from .model import *. The accompanying isort reorder in __init__.py is the expected ruff --fix output once the per-line # noqa: F401 was removed. The double # type: ignore # type: ignore in connection.py is also cleaned up. No runtime code paths touched, CodSpeed clean, coverage unchanged at 100%. Follows the established one-ruff-family-at-a-time cadence (#1678 PTH, #1679 PT006/PT007, #1683 B). Merge-ready.



Checklist

  • Correct PGH003 error codes chosen per import site
  • PGH004 F401/F403 codes cover all re-exports
  • No runtime behavior changes
  • Tests pass, coverage unchanged

Summary

Mechanical ruff PGH enablement: 10 protobuf import sites get the correct narrow [attr-defined] code, the model.py service-map case correctly uses [union-attr] (mypy keeps str | Any after the isinstance branch), and the __init__.py blanket # flake8: noqa becomes # ruff: noqa: F401, F403 which covers both the re-exports and the from .model import *. The accompanying isort reorder in __init__.py is the expected ruff --fix output once the per-line # noqa: F401 was removed. The double # type: ignore # type: ignore in connection.py is also cleaned up. No runtime code paths touched, CodSpeed clean, coverage unchanged at 100%. Follows the established one-ruff-family-at-a-time cadence (#1678 PTH, #1679 PT006/PT007, #1683 B). Merge-ready.


Automated review by Kōan7a65ec8

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.
@bluetoothbot
Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan/ruff-pgh was rebased onto main and review feedback was applied.

Stats

10 files changed, 11 insertions(+), 10 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on main enables PGH ruff rules or converts blanket type:ignore directives to specific code)
  • Rebased koan/ruff-pgh onto upstream/main
  • Pre-push CI check: previous run #26156579827 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/ruff-pgh to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@bdraco bdraco marked this pull request as ready for review May 20, 2026 12:16
Copilot AI review requested due to automatic review settings May 20, 2026 12:16
@bdraco bdraco merged commit 8c440b5 into esphome:main May 20, 2026
15 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@bdraco has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 18 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e810026b-3401-4742-afb8-81e3c977793e

📥 Commits

Reviewing files that changed from the base of the PR and between dc32bd4 and 47c0547.

📒 Files selected for processing (10)
  • aioesphomeapi/client.py
  • aioesphomeapi/client_base.py
  • aioesphomeapi/connection.py
  • aioesphomeapi/core.py
  • aioesphomeapi/log_reader.py
  • aioesphomeapi/log_runner.py
  • aioesphomeapi/model.py
  • aioesphomeapi/model_conversions.py
  • pyproject.toml
  • tests/test_log_runner.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables Ruff’s PGH (pygrep-hooks) rules to prevent blanket # type: ignore / # noqa directives from masking unrelated diagnostics, and updates existing ignores to be code-specific.

Changes:

  • Enable Ruff PGH rule family in pyproject.toml.
  • Convert existing # type: ignore uses to specific mypy codes (mostly attr-defined, plus one union-attr).
  • Replace a broad file-level suppression with a targeted Ruff file directive in aioesphomeapi/__init__.py.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyproject.toml Adds PGH to Ruff rule selection.
aioesphomeapi/__init__.py Uses # ruff: noqa: F401, F403 and narrows mypy ignore on api_pb2 imports.
aioesphomeapi/model.py Narrows # type: ignore to attr-defined (TYPE_CHECKING import) and union-attr (service-map conversion).
aioesphomeapi/model_conversions.py Narrows protobuf import ignore to attr-defined.
aioesphomeapi/log_runner.py Narrows protobuf import ignore to attr-defined.
aioesphomeapi/log_reader.py Narrows protobuf import ignore to attr-defined.
aioesphomeapi/core.py Narrows protobuf import ignore to attr-defined.
aioesphomeapi/connection.py Replaces duplicate blanket ignore with attr-defined on protobuf imports.
aioesphomeapi/client.py Narrows protobuf import ignore to attr-defined.
aioesphomeapi/client_base.py Narrows protobuf import ignore to attr-defined.
tests/test_log_runner.py Narrows protobuf import ignore to attr-defined.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyproject.toml
"G", # flake8-logging-format
"I", # isort
"PERF", # Perflint
"PGH", # pygrep-hooks
@bluetoothbot bluetoothbot deleted the koan/ruff-pgh branch May 20, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants