Skip to content

fix(ext.redis): type-check clean under redis 7.x and 8.x - #812

Merged
derks merged 2 commits into
mainfrom
fix/ext-redis-mypy-unused-ignore
Sep 10, 2026
Merged

derks merged 2 commits into
mainfrom
fix/ext-redis-mypy-unused-ignore

Conversation

@derks

@derks derks commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Summary

CI's comply gate fails on #811 (the automated pdm.lock bump of redis 7.4.0 → 8.1.0). redis 8.1 narrowed the return annotations on delete() and keys() (ResponseT → int | Awaitable[int]), which makes the two # type: ignore suppressions in RedisCacheHandler unused. warn_unused_ignores = true (pyproject.toml:193) turns an unused suppression into an error, so make comply exits 2.

Replacing both suppressions with typing.cast() fixes it. A cast is not a suppression directive, so warn_unused_ignores can never flag it — the handler type-checks clean under both redis 7.4.0 and 8.1.0.

This is a standalone fix; it is not the lock bump. pyproject.toml and pdm.lock are untouched and #811 lands separately.

Changes

cement/ext/ext_redis.py

  • delete() — res = cast(int, self.r.delete(key)), replacing int(res) > 0 # type: ignore[arg-type].
  • purge() — keys = cast('list[Any]', self.r.keys('*')), dropping # type: ignore[misc] from the delete(*keys) call.
  • One comment records the why: redis-py annotates sync and async client responses identically, and this handler is sync-only.
  • The # type: ignore[union-attr] on the res.decode() line in get() is deliberately untouched — still load-bearing under both redis versions.

CHANGELOG.md — [ext.redis] entry in the 3.0.17 - DEVELOPMENT / Bugs bucket.

No downstream constraint change

The alternative fix — flooring the redis extra to >=8 — was rejected. It would drop redis 7.x for downstream users, which the compatibility-first policy for the 3.0.x track rules out. The redis extra stays unpinned (redis = ["redis"]).

Acceptance status

# Criterion Verification Status
D1 Type-checks clean under redis 8.1.0 mypy --python-executable <redis-8.1.0-venv>/bin/python cement/ext/ext_redis.py → Success: no issues found ✅
D1 Type-checks clean under redis 7.4.0 make comply (ruff + mypy, installed redis 7.4.0) → exit 0 ✅
D2 Handler runtime behavior unchanged tests/ext/test_ext_redis.py — 5 passed, 100.00% coverage on cement/ext/ext_redis.py ✅
D2 Full suite green make test — 392 passed, 100.00% total coverage ✅
D3 Dependency surface untouched pyproject.toml / pdm.lock absent from the diff ✅

Files touched

CHANGELOG.md            |  6 ++++++
cement/ext/ext_redis.py | 12 +++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)

Test plan

  • make comply — ruff clean, mypy clean across 51 source files
  • mypy against a redis 8.1.0 venv — clean
  • mypy against redis 7.4.0 (local install) — clean
  • pdm run pytest tests/ext/test_ext_redis.py — 5 passed, 100% coverage
  • make test — 392 passed, 100% total coverage
  • Re-run CI on chore: Update pdm.lock #811 once this merges; the comply gate should go green

🤖 Generated with Claude Code

https://claude.ai/code/session_01RjdwAnb4UJjmDbTcVrHoCN

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with Redis 7.4.0 and 8.1.0 by ensuring delete and purge operations pass type validation cleanly.
  • Documentation
    • Added a changelog entry documenting the Redis compatibility fix.

derks and others added 2 commits September 10, 2026 09:22
redis 8.1 narrowed the delete()/keys() return annotations, making the
two type-ignore comments in delete() and purge() unused, which trips
warn_unused_ignores. typing.cast() is not a suppression directive, so
it type-checks clean under both redis 7.4.0 and 8.1.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjdwAnb4UJjmDbTcVrHoCN
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RjdwAnb4UJjmDbTcVrHoCN
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b97f1bb0-a7a3-46b8-acf1-eb480a7140af

📥 Commits

Reviewing files that changed from the base of the PR and between f94e5bd and 364ce6a.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • cement/ext/ext_redis.py

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The Redis extension now uses typing.cast() for deletion results and purge key collections. The development changelog records the type-checking fix for supported Redis versions.

Changes

Redis type-checking cleanup

Layer / File(s) Summary
Redis operation casts
cement/ext/ext_redis.py, CHANGELOG.md
The delete() method casts the Redis result to int. The purge() method casts the key collection to list[Any]. The changelog documents the replacement of unused type-ignore suppressions.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 364ce

This cleanup preserves Redis cache behavior while removing unused type suppressions. Type checks and tests pass, so the change is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing Redis extension type checking across redis 7.x and 8.x.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ext-redis-mypy-unused-ignore

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@derks
derks merged commit 4a1f352 into main Sep 10, 2026
14 checks passed
@derks
derks deleted the fix/ext-redis-mypy-unused-ignore branch September 12, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant