Skip to content

refactor: enable stricter ruff lints and broad exception checking - #956

Merged
allenporter merged 1 commit into
Python-roborock:mainfrom
allenporter:revisit_disabled_ruff_lints
Sep 12, 2026
Merged

refactor: enable stricter ruff lints and broad exception checking#956
allenporter merged 1 commit into
Python-roborock:mainfrom
allenporter:revisit_disabled_ruff_lints

Conversation

@allenporter

Copy link
Copy Markdown
Contributor

Description

This PR updates the Ruff configuration and codebase to align with repository engineering guidelines (AGENTS.md):

  1. Eliminate Global Ignores:

    • Cleared lint.ignore = [].
    • Scoped F403 to per-file-ignores explicitly only on specific __init__.py modules that perform wildcard re-exports.
    • Scoped E741 to an inline # noqa: E741 in containers.py where l is a wire payload field.
  2. Broad Exception Checking (BLE001):

    • Added BLE (flake8-blind-except) to lint.select.
    • Added file-level # ruff: noqa: BLE001 opt-out for roborock/cli.py.
    • Replaced except BaseException: with except Exception: in CLI debug parser.
    • Added targeted per-instance # noqa: BLE001 annotations on loop supervisors and trait query fallbacks.
  3. Enable High-Value Rule Sets:

    • Added B (bugbear), C4 (comprehensions), PIE (flake8-pie), A (builtins), PGH (pygrep-hooks), W (pycodestyle warnings), and clean conventions (YTT, FA, ICN, ISC).
    • Cleaned up raise ... from err (B904), strict parameter in zip() (B905), and type ignore tags (PGH003).
    • Added a TODO comment in pyproject.toml to enable ASYNC (flake8-async) in a dedicated follow-up PR.

Testing

  • uv run ruff check roborock tests passes.
  • uv run pre-commit run --all-files passes.
  • uv run pytest passes (983 tests, 92 snapshots).

Copilot AI lite review requested due to automatic review settings September 12, 2026 20:31
@allenporter
allenporter requested a review from Lash-L September 12, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

roborock/util.py has an unresolved typing error, and the CLI’s file-wide BLE001 opt-out should be narrowed.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR tightens Ruff linting and applies related code-quality and typing cleanups.

Changes:

  • Enables additional Ruff rule families with scoped ignores.
  • Updates exception handling, chaining, and type-ignore annotations.
  • Cleans up comprehensions, zip() usage, fixtures, and defaults.
File summaries
File Changes
tests/test_web_api.py Removes redundant fixture body.
tests/fixtures/pahomqtt_fixtures.py Adds warning stack levels.
tests/fixtures/local_async_fixtures.py Adds warning stack level.
tests/data/test_code_mappings.py Renames a shadowing parameter.
roborock/util.py Removes a type ignore from list padding; typing issue remains.
roborock/testing/v1_simulator.py Annotates intentional broad catches.
roborock/protocols/b01_q7_protocol.py Adds exception chaining.
roborock/protocols/a01_protocol.py Adds exception chaining.
roborock/protocol.py Updates typing directives and comprehensions.
roborock/mqtt/roborock_session.py Annotates reconnect exception handling.
roborock/map/b01_q10_map_parser.py Clarifies zip() strictness and range usage.
roborock/map/b01_grid_layers.py Makes coordinate zipping strict.
roborock/devices/transport/local_channel.py Annotates keep-alive exception handling.
roborock/devices/traits/v1/rooms.py Annotates fallback exception handling.
roborock/devices/traits/v1/clean_summary.py Annotates conversion fallback handling.
roborock/devices/traits/__init__.py Suppresses an intentional abstract-base warning.
roborock/devices/rpc/b01_q7_channel.py Annotates response parsing exceptions.
roborock/device_features.py Removes an unnecessary type ignore.
roborock/data/v1/v1_code_mappings.py Narrows a type-ignore annotation.
roborock/data/containers.py Simplifies exception handling and defaults.
roborock/data/code_mappings.py Narrows a type-ignore annotation.
roborock/cli.py Updates exception handling and typing directives; file-wide BLE001 opt-out should be narrowed.
roborock/broadcast_protocol.py Annotates packet parsing exceptions.
pyproject.toml Enables expanded Ruff rules and scoped ignores.
Review details

Suppressed comments (1)

roborock/cli.py:25

  • This module-level opt-out disables BLE001 for every broad catch in the CLI and for any future one, so the new lint no longer checks this file at all. Please remove the file-wide directive and annotate only the specific command/parser boundaries that intentionally continue after arbitrary failures; that keeps accidental broad catches visible to the stricter configuration.
# ruff: noqa: BLE001
  • Files reviewed: 24/24 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread roborock/util.py
@allenporter
allenporter merged commit 28a6edc into Python-roborock:main Sep 12, 2026
7 checks passed
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