Skip to content

Ruff misc: small comprehension/perf grab-bag (PERF102, SIM105, RUF005, C4xx, RUF015, stray RUF046) #498

Closed

Description

@squid-protocol

Objective

Part of the ruff lint baseline cleanup (several 1-2 count rule families -- C401 (unnecessary generator where a builtin call would do), C403 (unnecessary list comprehension where a set/generator would do), C414 (redundant cast (e.g. list()/sorted() double-wrapping)), C416 (unnecessary comprehension that just rebuilds the same collection), C419 (unnecessary comprehension inside a call that takes an iterable directly), PERF102 (iterating .items() when only keys or only values are used), RUF005 (list concatenation via + instead of unpacking), RUF015 (allocating a full list just to grab the first element), SIM105 (try/except/pass that could be contextlib.suppress(...))). Chunked out of the larger sub-issue this replaces, so it's a manageable, self-contained pickup.

Findings

  • gitgalaxy/core/detector.py:2158 (C403) -- Unnecessary list comprehension (rewrite as a set comprehension)
  • gitgalaxy/core/guidestar_lens.py:139 (C401) -- Unnecessary generator (rewrite as a set comprehension)
  • gitgalaxy/core/network_risk_sensor.py:183 (C419) -- Unnecessary list comprehension
  • gitgalaxy/metrics/signal_processor.py:498 (RUF046) -- Value being cast to int is already an integer
  • gitgalaxy/metrics/signal_processor.py:549 (C419) -- Unnecessary list comprehension
  • gitgalaxy/recorders/audit_recorder.py:290 (C416) -- Unnecessary dict comprehension (rewrite using dict())
  • gitgalaxy/recorders/audit_recorder.py:307 (C414) -- Unnecessary list() call within sorted()
  • gitgalaxy/recorders/gpu_recorder.py:285 (C414) -- Unnecessary list() call within sorted()
  • gitgalaxy/recorders/record_keeper.py:700 (RUF005) -- Consider iterable unpacking instead of concatenation
  • gitgalaxy/recorders/record_keeper.py:771 (RUF005) -- Consider iterable unpacking instead of concatenation
  • gitgalaxy/security/security_auditor.py:359 (RUF046) -- Value being cast to int is already an integer
  • gitgalaxy/standards/language_lens.py:132 (SIM105) -- Use contextlib.suppress(re.error) instead of try-except-pass
  • gitgalaxy/standards/language_lens.py:760 (PERF102) -- When using only the values of a dict use the values() method
  • gitgalaxy/standards/language_lens.py:897 (PERF102) -- When using only the values of a dict use the values() method
  • gitgalaxy/tools/cobol_to_cobol/cobol_jcl_auditor.py:107 (RUF015) -- Prefer next(iter(generated_metrics["exec_pgms"])) over single element slice

Approach

Each of these rules only has 1-2 occurrences, so they're bundled into one grab-bag rather than filed as individual one-line issues. Each finding is independent -- fix whichever you like, in any order.

Fix in a small PR, removing resolved entries from tests/ruff_audit_baseline.json (see tests/ruff_audit.py's module docstring for the regen command).

Parent: #469

Activity

  1. added
    good first issue
    python
    refactor
    priority: low
    on Jul 26, 2026
  2. squid-protocol commented on Aug 9, 2026

    @squid-protocol
    OwnerAuthor

    FYI while doing a pass to check for staleness across the "good first issue" label: 2 of the 15 findings listed here have already been fixed incidentally (no longer flagged by ruff check, no longer in the baseline) -- looks like a side effect of unrelated edits to these files, not a targeted fix:

    • gitgalaxy/core/network_risk_sensor.py (was :183) C419
    • gitgalaxy/metrics/signal_processor.py (was :549) C419

    The other 13 findings across the remaining files are still live and confirmed against a fresh ruff check (pinned 0.16.0) + the current baseline. Whoever picks this up can drop those two from the findings list -- nothing else to do for them specifically, they just won't show up when you go looking.

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

    good first issuepriority: lowpythonrefactor

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions