Skip to content

[REFACTOR] Ruff: simplification, comprehensions, and perflint findings #474

Closed

Description

@squid-protocol

Objective

Work down the code-quality/readability slice of the ruff lint baseline (#469) -- flake8-simplify, flake8-comprehensions, and perflint findings. None of these are bugs; all are "this could be clearer or faster written a different way."

Rule Count What it flags
`PERF401` 21 a `for` loop that just `.append()`s could be a list comprehension
`SIM102` 17 nested `if` that could collapse into one `if ... and ...`
`RUF046` 15 unnecessary `int(...)` cast around a value that's already an int
`PERF203` 11 `try`/`except` inside a loop body (has per-iteration overhead in some Python versions; often unavoidable here given per-file fault isolation, worth a case-by-case look rather than blanket restructuring)
`SIM118` 9 `key in d.keys()` instead of `key in d`
`SIM108` 5 if/else block that could be a ternary
`PERF102` 4 iterating `.items()` when only keys or only values are used
`SIM105` 2 `try`/`except`/`pass` that could be `contextlib.suppress(...)`
`RUF005` 2 list concatenation via `+` instead of unpacking
`C414`/`C419` 2 each redundant cast/comprehension-in-call
`C401`/`C403`/`C416` 1 each unnecessary generator/comprehension where a builtin call would do
`RUF015` 1 allocating a full list just to grab the first element

94 findings total. Lowest priority of the three sub-issues -- pure readability/micro-perf, safe to pick off opportunistically rather than as a dedicated push.

Approach

`PERF203`'s try/except-in-loop hits deserve a quick look before fixing mechanically -- moving the try outside the loop can change error-isolation semantics (one bad iteration currently doesn't kill the rest of the batch; hoisting the try could change that). Confirm the loop body's fault-isolation intent before restructuring.

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
    priority: low
    on Jul 25, 2026
  2. squid-protocol commented on Jul 26, 2026

    @squid-protocol
    OwnerAuthor

    Split into smaller, self-contained chunks for good-first-issue accessibility instead of one 94-finding sub-issue: #488, #489, #490, #491, #492, #493, #494, #495, #496, #497, #498. Closing this in favor of those.

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

    performancepriority: lowpythonrefactor

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions