chore(tooling): anchor coverage excludes, fix pre-commit hooks, tidy ruff ignores - #277
Merged
Merged
Conversation
…ruff ignores - Coverage: anchor the bare "pass" and "..." exclude_lines patterns. Unanchored, they also excluded every line (and block) containing "password", "bypass" or "Field(...", such as the whole Redis constructor body and the backend-bypass branch in @cache. - pre-commit: drop the duplicate end-of-file-fixer, stop running uv-lock with --upgrade, and give the mypy hook the packages the code imports (redis, orjson, pymemcache, PyJWT) instead of unrelated stubs. - Ruff: drop the stale PLW0603 ignores, fix the two remaining B904 sites (chain the optional-import ImportError), scope S105 and PLR0917 to the files that need them, and allow fastapi.Depends through extend-immutable-calls instead of ignoring B008. Closes #190 Closes #191 Closes #192
This was referenced Sep 27, 2026
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.
Summary
Closes #190, closes #191, closes #192 (parts of #124).
#190: anchor the coverage exclude patterns
The patterns
"pass"and"\\.\\.\\."are regexes searched anywhere in a line. An excluded line that opens a block excludes the whole block. So they hid more than the issue listed:AsyncRedisCacheBackend.__init__body (lines 109–181), through itspasswordparameter;bypass_backend = ...and theif bypass_backend:branch in@cache;Field(...)lines and aclear_patternwarning that says "pass".They are now anchored to bare
pass/...statements, optionally followed by a comment.Coverage below was measured locally with the live Redis/Memcached tests skipped, so it is lower than CI's live run:
That is 47 more statements counted. Only one of them is uncovered locally: a Redis warning line (
redis.py:447) that the live tests exercise.fail_understays at 90. A run without live servers sits at about 94%, so raising it past ~93 would fail local runs that have no servers. A separate, higher gate for the live CI job would be the place to raise it.#191: pre-commit
Removed the second
end-of-file-fixer.uv-lockno longer runs with--upgrade, so pre-commit no longer bumpsuv.lock. This PR was committed with every hook running, and noSKIP=uv-lockwas needed.The mypy hook's
additional_dependencies:types-requests,types-PyYAMLandtypes-aiofiles; nothing imports them;redis,orjson,pymemcacheandPyJWT, the optional packages the code imports.No new mypy errors surfaced.
docs/DEVELOPMENT.mdnow saysuv-lockonly re-resolves the lockfile and does not upgrade it.#192: ruff ignores
PLW0603: the per-file ignore onproxy.pywas stale (nogloballeft) and is removed.B904was not stale. Two optional-import guards re-raised withoutfrom, inmemcached.pyandredis.py. They now chain theImportError(raise CacheXError(msg) from exc), and the global ignore is removed.S105moved to per-file ignores:session/manager.py:token_format = "simple"is not a password;tests/**.PLR0917moved to the two public constructors that need it, inbackends/redis.pyandlock.py. The private_persisthelper insession/middleware.pygot an inlinenoqa, next to its existingPLR0913.B008is replaced bylint.flake8-bugbear.extend-immutable-calls = ["fastapi.Depends"].Dependsis the only call B008 flags, in both the package and the tests.Verification
uv run pre-commit run --all-files: passes, anduv.lockis byte-identical afterwards.uv lock --check: passes.uv run mypy fastapi_cachex --strict: clean.uv run ruff check fastapi_cachex tests scripts: clean. Also ran it with only--select PLW0603and only--select B904: both clean.uv run pytestwith live servers skipped: 814 passed, 191 skipped.zensical build --strictfor the English docs passes.DEVELOPMENT.mdhas no zh-TW copy.CHANGELOG
None: tooling only. The one library change is that the "not installed"
CacheXErrornow chains the originalImportError, and I judged it too small for an entry.