chore: fix ruff lint findings, restore green CI lint gate - #18
Merged
Conversation
ruff check . had 161 pre-existing findings on main, unrelated to any
recent work, that had been failing CI's "Lint & Test" job across the
last several merges. Fixes all of them so the lint gate is meaningful
again.
Before/after: 161 -> 0.
Auto-fixed via `ruff check . --fix` (safe fixes only) -- 121 findings,
no behavior change, import reordering and typing modernization only:
- UP006 (52): `List`/`Dict`/`Set`/`Tuple` -> builtin generics (`list`/`dict`/...)
- I001 (30): import block sorting
- UP035 (15): drop deprecated `typing` imports made redundant by UP006
- F401 (11): unused imports
- RUF010 (8): `f"{str(e)}"` -> `f"{e!s}"`
- UP045 (4): `Optional[X]` -> `X | None`
- UP007 (1): `Union[X, Y]` -> `X | Y`
Manually fixed (real, minor issues) -- 15 findings:
- RUF013 (8, 4 sites): implicit-Optional params (`x: str = None`) made
explicit (`x: str | None = None`) in index/vector_store.py and
rag/engine.py
- SIM117 (5): nested `with` statements in tests collapsed into one
parenthesized `with (...)` -- purely mechanical, same context
managers
- SIM102 (1): collapsed a nested `if` into one condition in
api/main.py's guard_requests middleware
- SIM118 (1): `for node in self.edges.keys()` -> `for node in
self.edges` in index/graph_store.py
- E722 + S112 (1 site, rag/query_router.py): bare `except: continue`
around a per-line JSON parse narrowed to the actual exception types
(JSONDecodeError/UnicodeDecodeError/AttributeError/KeyError) and
given a print so a parse failure is no longer silently swallowed
- TRY004 (1): `_embed()`'s type-check now raises `TypeError` instead
of `ValueError` (the right exception for a type check) -- updated
the one test asserting on it to match
- EXE001 (1): `scripts/run_eval.py` has a shebang but wasn't
executable; chmod +x to match, consistent with the other script
in scripts/
- F841 (4): unused mock variables in tests -- rather than delete them,
added the assertions their surrounding tests were clearly missing
(`mock_file`/`mock_pload`/`mock_retrieve` were bound but never
checked; asserting on them now actually verifies the mocked call
happened, matching the pattern already used by sibling assertions
in the same tests)
Scoped `# noqa: BLE001` (17 sites, each with an inline reason) for
`except Exception` at deliberate error-isolation boundaries -- these
convert an arbitrary failure into a safe fallback (empty list, inline
error string/token, HTTP 500, skip-and-continue) so one bad chunk/tool
step/subsystem/request doesn't crash a larger operation. Narrowing
these to specific exception types would risk missing failure modes
these boundaries exist to catch, defeating their purpose. Sites:
api/routes/rag.py (3), ingestion/doc_loader.py (1), rag/engine.py (3),
rag/query_router.py (4), rag/tool_executor.py (4),
scripts/build_index.py (1), scripts/run_eval.py (1).
Verified: `ruff check .` -> "All checks passed!" (zero findings) and
`pytest -q` -> 199 passed, both after the full set of changes above.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XaLTXgv4NNGzg2snnnYRZV
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.
What
ruff check .(CI's "Lint & Test" job) has been failing onmainacross the last several merged PRs — 161 pre-existing findings, entirely unrelated to any of the recent security/config/docs work. This restores a green, meaningful lint gate.Before / after
ruff check .→All checks passed!Findings by rule code (before)
List/Dict/Set/Tuple→ builtin genericsexcept Exceptiontypingimportsstr()in f-stringOptional(x: str = None)withstatementsOptional[X]→X | NoneifUnion[X, Y]→X | Ykey in dict.keys()→key in dictexcept:try/except/continuewith no loggingWhat was auto-fixed vs. manually fixed vs. noqa'd
Auto-fixed by
ruff check . --fix(safe fixes only) — 121 findings, zero behavior change:UP006, I001, UP035, F401, RUF010, UP045, UP007 — all pure import reordering / typing modernization (
List→list,Optional[X]→X | None, dropping now-unused imports,f"{str(e)}"→f"{e!s}").Manually fixed (real, minor issues) — 15 findings:
param: str = None→param: str | None = Noneinindex/vector_store.pyandrag/engine.py.withstatements in tests collapsed into one parenthesizedwith (...)— same context managers, purely mechanical.ifinapi/main.py'sguard_requestsmiddleware into one condition.for node in self.edges.keys()→for node in self.edgesinindex/graph_store.py.rag/query_router.py): a bareexcept: continuearound a per-line JSON parse was narrowed to the actual exception types (JSONDecodeError/UnicodeDecodeError/AttributeError/KeyError) and now prints before continuing, so a parse failure is no longer silently swallowed.RAGEngine._embed()'s type check now raisesTypeErrorinstead ofValueError(the correct exception for a type-validation failure) — updated the one test asserting on it (test_engine_embed_invalid_type) to match.scripts/run_eval.pyhad a shebang but wasn't executable;chmod +xto match, consistent withscripts/check_and_reindex.sh.mock_file,mock_pload,mock_retrieve×2) and never asserted on it. Rather than delete the unused variable, added the assertion the surrounding test was clearly missing — each now verifies the mocked call actually happened, matching the pattern already used by sibling assertions in the same tests (e.g.mock_mkdirs.assert_called_once_with(...)right next to it).Scoped
# noqa: BLE001— 17 sites, each with an inline reason, no blanket ignore:Every one of these is
except Exceptionat a deliberate error-isolation boundary — converting an arbitrary failure into a safe fallback (empty list, inline error string/token, HTTP 500, skip-and-continue) so one bad chunk/tool-step/subsystem/request doesn't crash a larger operation:api/routes/rag.py(3): engine-access wrapper, top-level/rag/queryHTTP handler, SSE stream generatoringestion/doc_loader.py(1): per-file read during the indexing walkrag/engine.py(3): optional CrossEncoder load, LLM call, LLM streamingrag/query_router.py(4): per-source search (vector/graph/plugin) + streamingrag/tool_executor.py(4): per-step dispatch + per-tool search (vector/graph/plugin)scripts/build_index.py(1): per-chunk embed during batch indexingscripts/run_eval.py(1): per-query evalNarrowing any of these to specific exception types would risk missing the failure modes the boundary exists to catch, defeating its purpose — that's why they're
noqa'd with a reason rather than "fixed."Verification
Confirmed 199 passed — same count as before this change — so none of the auto-fixes (import reordering, typing syntax) or manual fixes altered behavior.
CI
This should turn
.github/workflows/ci.yml's "Lint & Test" job green again for the first time in several merges.🤖 Generated with Claude Code