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
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/passthat could becontextlib.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 comprehensiongitgalaxy/metrics/signal_processor.py:498(RUF046) -- Value being cast tointis already an integergitgalaxy/metrics/signal_processor.py:549(C419) -- Unnecessary list comprehensiongitgalaxy/recorders/audit_recorder.py:290(C416) -- Unnecessary dict comprehension (rewrite usingdict())gitgalaxy/recorders/audit_recorder.py:307(C414) -- Unnecessarylist()call withinsorted()gitgalaxy/recorders/gpu_recorder.py:285(C414) -- Unnecessarylist()call withinsorted()gitgalaxy/recorders/record_keeper.py:700(RUF005) -- Consider iterable unpacking instead of concatenationgitgalaxy/recorders/record_keeper.py:771(RUF005) -- Consider iterable unpacking instead of concatenationgitgalaxy/security/security_auditor.py:359(RUF046) -- Value being cast tointis already an integergitgalaxy/standards/language_lens.py:132(SIM105) -- Usecontextlib.suppress(re.error)instead oftry-except-passgitgalaxy/standards/language_lens.py:760(PERF102) -- When using only the values of a dict use thevalues()methodgitgalaxy/standards/language_lens.py:897(PERF102) -- When using only the values of a dict use thevalues()methodgitgalaxy/tools/cobol_to_cobol/cobol_jcl_auditor.py:107(RUF015) -- Prefernext(iter(generated_metrics["exec_pgms"]))over single element sliceApproach
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(seetests/ruff_audit.py's module docstring for the regen command).Parent: #469