fix: resolve ruff-check lint errors in non-template Python files#245
Open
TheSaiEaranti wants to merge 1 commit into
Open
fix: resolve ruff-check lint errors in non-template Python files#245TheSaiEaranti wants to merge 1 commit into
TheSaiEaranti wants to merge 1 commit into
Conversation
ruff-check reported 45 findings across 12 tracked, non-template Python files: F541 (35), F841 (5), F401 (4) and F821 (1). Non-template findings are now zero. Mechanical fixes, applied with `ruff check --fix`: - F541: drop the f prefix from f-strings that contain no placeholders. - F401: remove genuinely unused imports (`typing.Union` in validate_custom_metrics.py, `INT` in test_safe_query.py; the latter is not reachable through the module's `globals()` test discovery, which selects only callables named `test_*`). Reviewed individually: - tools/validate-urls.py imports httpx lazily inside functions, so the module scope annotation `client: "httpx.AsyncClient"` had no binding to resolve. Add a TYPE_CHECKING guarded import, which keeps the lazy import behaviour and leaves the module importable without httpx installed. - verify-traceability.py computed overall_total, overall_impl and overall_pct in generate_html but never rendered them, unlike rules_pct and reqs_pct. Remove all three, since dropping only overall_pct would leave the other two unused. - post_process_drawio.py computed actor_x2 but never used it. The three *_source_template.py files are customer facing starter templates whose unused imports and example variables are deliberate scaffolding, so they get a file level `# ruff: noqa: F401, F841` rather than having that scaffolding stripped, per the suggestion in the issue. The 12 code_templates/*.py files are left untouched; their 44 invalid-syntax findings and 2 E402 findings are awslabs#214. Pre-existing repo wide ruff-format failures are also out of scope and unchanged at 25 files before and after. Fixes awslabs#218
TheSaiEaranti
requested review from
a team,
krokoko,
scottschreckengaust and
theagenticguy
July 25, 2026 09:33
TheSaiEaranti
requested review from
Morlej,
amaksimo,
anwesham-lab,
jaichabria,
pkale,
praba2210 and
spencercorwin
July 25, 2026 09:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #218
Scope
ruff check(v0.15.0, the pinned pre-commit rev) reports 91 findings onmain. They split cleanly in two:code_templates/*.pyinvalid-syntax, 2E402)F54135,F8415,F4014,F8211)Non-template findings are now 0. The 46 belonging to #214 are unchanged.
Two notes on how this differs from the issue description, which was written on 2026-07-06:
E402is no longer among the non-template codes — both remainingE402findings are insidecode_templates/, so they belong to pre-commit: 12code_templates/*.pyfiles fail Python-parse hooks (check-ast, ruff-format) #214. The non-template codes are nowF541,F841,F401andF821.Mechanical fixes
Applied with
ruff check --fix(safe fixes only; no--unsafe-fixes):F541(35) — dropped thefprefix from f-strings with no placeholders.F401(2 of 4) — removedtyping.Unionfromvalidate_custom_metrics.pyandINTfromtest_safe_query.py. I checked thatINTis not reachable through that file'sglobals()-based fallback test discovery, which selects only callables namedtest_*;INT_INJECTIONSis a separate name and is still used.Reviewed individually
tools/validate-urls.py—F821undefined namehttpxThis is a PEP 723 inline script that imports
httpxlazily insidecheck_urlandmain, so the module-scope annotationclient: "httpx.AsyncClient"had nothing to resolve against. Added aTYPE_CHECKING-guarded import rather than anoqa, which keeps the lazy-import behaviour intact — I verified the module still imports withhttpxabsent, and the annotation is preserved.verify-traceability.py—F841overall_pctgenerate_htmlcomputedoverall_total,overall_implandoverall_pct, but onlyrules_pctandreqs_pctare ever rendered. Removing justoverall_pctwould have left the other two unused, so all three go. This looks like an intended "overall" dashboard stat that was never wired into the HTML — worth a follow-up if you want that row displayed rather than deleted.post_process_drawio.py—F841actor_x2Removed. Flagging what it hints at, since it may be worth its own issue: the overlap test on the next line is
which only detects an actor whose left edge is inside the AWS Cloud. An actor starting left of the cloud and extending into it is not detected.
actor_x2is exactly the term a full interval-overlap test would need, so this reads like an unfinished check. I have not changed that behaviour here — it is a layout change, not a lint fix, and should be your call.Templates
The three
*_source_template.pyfiles are customer-facing starter templates ("INITIAL SUGGESTION ONLY - MUST BE CUSTOMIZED"), wherefrom typing import Dict, Any, List, Optional # For type hintsand the example variables are deliberate scaffolding for the reader. Stripping them would remove the thing the template exists to provide, so each gets a file-level directive instead, as the issue suggests:Verification
ruff check .→ non-template findings 0; remaining 46 are allcode_templates/*(pre-commit: 12code_templates/*.pyfiles fail Python-parse hooks (check-ast, ruff-format) #214).ast.parse) and byte-compile.tools/evals/databases-on-aws/dsql/scripts/test_safe_query.py→ 63 passed, 0 failed.validate-urls.pyimports at module scope withhttpxnot installed.verify-traceability.pyandpost_process_drawio.pybehave identically tomainon import (the latter raises the same pre-existingdefusedxmlAttributeErrorin my environment both before and after).Out of scope:
ruff-formatfails repo-wide onmain— 25 files, including files this PR touches. That count is 25 before and 25 after, so nothing here adds to it. Running the formatter would turn this into an unrelated 25-file diff, so I left it alone; happy to file it separately if it is not already tracked under #213.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.