fix(ext.redis): type-check clean under redis 7.x and 8.x - #812
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe Redis extension now uses ChangesRedis type-checking cleanup
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation 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.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
Summary
CI's
complygate fails on #811 (the automatedpdm.lockbump ofredis7.4.0 → 8.1.0). redis 8.1 narrowed the return annotations ondelete()andkeys()(ResponseT→int | Awaitable[int]), which makes the two# type: ignoresuppressions inRedisCacheHandlerunused.warn_unused_ignores = true(pyproject.toml:193) turns an unused suppression into an error, somake complyexits 2.Replacing both suppressions with
typing.cast()fixes it. A cast is not a suppression directive, sowarn_unused_ignorescan 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.tomlandpdm.lockare untouched and #811 lands separately.Changes
cement/ext/ext_redis.pydelete()—res = cast(int, self.r.delete(key)), replacingint(res) > 0 # type: ignore[arg-type].purge()—keys = cast('list[Any]', self.r.keys('*')), dropping# type: ignore[misc]from thedelete(*keys)call.# type: ignore[union-attr]on theres.decode()line inget()is deliberately untouched — still load-bearing under both redis versions.CHANGELOG.md—[ext.redis]entry in the3.0.17 - DEVELOPMENT/ Bugs bucket.No downstream constraint change
The alternative fix — flooring the
redisextra 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. Theredisextra stays unpinned (redis = ["redis"]).Acceptance status
mypy --python-executable <redis-8.1.0-venv>/bin/python cement/ext/ext_redis.py→Success: no issues foundmake comply(ruff + mypy, installed redis 7.4.0) → exit 0tests/ext/test_ext_redis.py— 5 passed, 100.00% coverage oncement/ext/ext_redis.pymake test— 392 passed, 100.00% total coveragepyproject.toml/pdm.lockabsent from the diffFiles touched
Test plan
make comply— ruff clean, mypy clean across 51 source filesmypyagainst a redis 8.1.0 venv — cleanmypyagainst redis 7.4.0 (local install) — cleanpdm run pytest tests/ext/test_ext_redis.py— 5 passed, 100% coveragemake test— 392 passed, 100% total coveragecomplygate should go green🤖 Generated with Claude Code
https://claude.ai/code/session_01RjdwAnb4UJjmDbTcVrHoCN
Summary by CodeRabbit