Skip to content

chore(tooling): anchor coverage excludes, fix pre-commit hooks, tidy ruff ignores - #277

Merged
allen0099 merged 1 commit into
masterfrom
chore/tooling-config-190-191-192
Sep 27, 2026
Merged

allen0099 merged 1 commit into
masterfrom
chore/tooling-config-190-191-192

Conversation

@allen0099

Copy link
Copy Markdown
Owner

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:

  • the entire AsyncRedisCacheBackend.__init__ body (lines 109–181), through its password parameter;
  • bypass_backend = ... and the if bypass_backend: branch in @cache;
  • Field(...) lines and a clear_pattern warning 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:

Statements Coverage
before 2372 93.86%
after 2419 93.90%

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_under stays 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-lock no longer runs with --upgrade, so pre-commit no longer bumps uv.lock. This PR was committed with every hook running, and no SKIP=uv-lock was needed.

  • The mypy hook's additional_dependencies:

    • dropped types-requests, types-PyYAML and types-aiofiles; nothing imports them;
    • added redis, orjson, pymemcache and PyJWT, the optional packages the code imports.

    No new mypy errors surfaced.

  • docs/DEVELOPMENT.md now says uv-lock only re-resolves the lockfile and does not upgrade it.

#192: ruff ignores

  • PLW0603: the per-file ignore on proxy.py was stale (no global left) and is removed.
  • B904 was not stale. Two optional-import guards re-raised without from, in memcached.py and redis.py. They now chain the ImportError (raise CacheXError(msg) from exc), and the global ignore is removed.
  • S105 moved to per-file ignores:
    • session/manager.py: token_format = "simple" is not a password;
    • tests/**.
  • PLR0917 moved to the two public constructors that need it, in backends/redis.py and lock.py. The private _persist helper in session/middleware.py got an inline noqa, next to its existing PLR0913.
  • B008 is replaced by lint.flake8-bugbear.extend-immutable-calls = ["fastapi.Depends"]. Depends is the only call B008 flags, in both the package and the tests.
  • CLAUDE.md is updated to match.

Verification

  • uv run pre-commit run --all-files: passes, and uv.lock is 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 PLW0603 and only --select B904: both clean.
  • uv run pytest with live servers skipped: 814 passed, 191 skipped.
  • zensical build --strict for the English docs passes. DEVELOPMENT.md has no zh-TW copy.

CHANGELOG

None: tooling only. The one library change is that the "not installed" CacheXError now chains the original ImportError, and I judged it too small for an entry.

…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
@allen0099 allen0099 added this to the 0.3.8 milestone Sep 26, 2026
@allen0099 allen0099 added the enhancement New feature or request label Sep 26, 2026
@allen0099
allen0099 merged commit 1e72a13 into master Sep 27, 2026
11 checks passed
@allen0099
allen0099 deleted the chore/tooling-config-190-191-192 branch September 27, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

1 participant