Skip to content

[REFACTOR] Ruff: exception-handling and dead-code hygiene (S110, ARG, B007, RUF012/059, F841) #473

Closed

Description

@squid-protocol

Objective

Work down the "real bug-shaped" slice of the ruff lint baseline (#469) -- unused arguments/variables, mutable default gotchas, and silent exception swallowing.

Rule Count What it flags
`ARG002` 14 unused method argument
`S110` 22 `try`/`except`/`pass` with no logging
`RUF012` 5 mutable default value in a class attribute (the classic "shared mutable default" footgun)
`B007` 5 loop control variable never used inside the loop body
`ARG001` 4 unused function argument
`RUF059` 3 a variable unpacked from a tuple/etc. but never used
`F841` 2 assigned but never used local variable

55 findings total.

Approach

`S110` is the largest bucket here, and a heads-up on scope: many of these are almost certainly this codebase's deliberate `except Exception: pass` fault-isolation pattern (skip a malformed regex match, continue scanning the rest of the file) documented throughout as "DEFENSIVE ARCHITECTURE" -- see the rationale in #469 for why `BLE001` (a stricter, more disruptive version of this same idea) was excluded from the rule selection entirely. `S110`'s ask is much cheaper though: add a `self.logger.debug(...)` line inside the `except`, not restructure the exception handling. That's almost always the right fix here, not suppression.

`ARG001`/`ARG002` findings should be checked against interface/override requirements first (an unused `self` or an intentionally-unused override parameter isn't a bug) before assuming it's dead.

Fix in small PRs, removing resolved entries from `tests/ruff_audit_baseline.json` (#469) as each is resolved.

Parent: #469

Activity

  1. added
    python
    refactor
    on Jul 25, 2026
  2. squid-protocol commented on Jul 25, 2026

    @squid-protocol
    OwnerAuthor

    S110 (22/22) done in #476 -- also fixed a real data-integrity issue found while tracing through the pattern: `network_risk_sensor.py`'s macro network metrics (modularity/assortativity/cyclic_density/avg_path_length/articulation_points) were silently defaulting to `0.0`/`0` on computation failure, indistinguishable from a genuine zero measurement. Now default to `None` (matching the existing `zero_dependency_mode` convention), with consumers no longer papering over that with their own fallback. See #476 for the full writeup.

    Remaining in this issue's scope: `ARG001`/`ARG002` (unused args, 18), `RUF012` (mutable class defaults, 5), `B007` (unused loop vars, 5), `RUF059` (unused unpacked vars, 3), `F841` (unused locals, 2) -- 33 findings.

    Baseline: 241 -> 217.

  3. added a commit that references this issue on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumpythonrefactor

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions