fix: use Redis' built in types & fix type errors#822
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #822 +/- ##
========================================
+ Coverage 38.2% 44.5% +6.4%
========================================
Files 48 48
Lines 3776 3791 +15
Branches 301 69 -232
========================================
+ Hits 1440 1686 +246
- Misses 2035 2036 +1
+ Partials 301 69 -232
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fe662d1 to
f2efd69
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates django-redis’s Redis client wrappers to rely on redis’s built-in typing (dropping types-redis) and adjusts method signatures/return types to better match redis-py behavior, while also addressing some type-checker friction around key/member encoding.
Changes:
- Removed
types-redisfrom the typing dependency group and switched toredis.typingtypes where needed. - Narrowed many Redis key parameters from
KeyTtostrand refined protocol typing (CacheKey,encode(..., allow_int=...)overloads). - Updated sorted-set (ZSET) wrappers to align return types with Redis commands and reduce type casts/ignores.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Drops types-redis from typing extras to use redis’s built-in typing. |
django_redis/client/sharded.py |
Updates several set-operation key parameter annotations to str. |
django_redis/client/mixins/sorted_sets.py |
Refines ZSET wrappers, adds casts/types, and changes member encoding behavior. |
django_redis/client/mixins/protocols.py |
Updates the protocol to use CacheKey and adds overloads for encode(). |
django_redis/client/default.py |
Broad typing refactor for keys and encoding overloads; improves decoding for keys/hkeys when Redis returns str. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def zrank( | ||
| self, | ||
| key: KeyT, | ||
| key: str, | ||
| value: Any, | ||
| withscore: bool = False, | ||
| version: int | None = None, | ||
| client: Redis | None = None, | ||
| ) -> int | None: | ||
| ) -> int | list[Any] | None: | ||
| """Get the rank (index) of member in sorted set, ordered low to high.""" | ||
| if client is None: | ||
| client = self.get_client(write=False) | ||
|
|
||
| key = self.make_key(key, version=version) | ||
| value = self.encode(value) | ||
| rank = client.zrank(key, value) | ||
|
|
||
| return int(rank) if rank is not None else None | ||
| return client.zrank( | ||
| self.make_key(key, version=version), | ||
| self.encode(value, allow_int=False), | ||
| withscore=withscore, | ||
| ) |
| def zrank( | ||
| self, | ||
| key: KeyT, | ||
| key: str, | ||
| value: Any, | ||
| withscore: bool = False, | ||
| version: int | None = None, | ||
| client: Redis | None = None, | ||
| ) -> int | None: | ||
| ) -> int | list[Any] | None: | ||
| """Get the rank (index) of member in sorted set, ordered low to high.""" | ||
| if client is None: | ||
| client = self.get_client(write=False) | ||
|
|
||
| key = self.make_key(key, version=version) | ||
| value = self.encode(value) | ||
| rank = client.zrank(key, value) | ||
|
|
||
| return int(rank) if rank is not None else None | ||
| return client.zrank( | ||
| self.make_key(key, version=version), | ||
| self.encode(value, allow_int=False), | ||
| withscore=withscore, | ||
| ) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
No description provided.