Skip to content

fix: use Redis' built in types & fix type errors#822

Merged
terencehonles merged 2 commits into
jazzband:masterfrom
terencehonles:fix-types
May 30, 2026
Merged

fix: use Redis' built in types & fix type errors#822
terencehonles merged 2 commits into
jazzband:masterfrom
terencehonles:fix-types

Conversation

@terencehonles
Copy link
Copy Markdown
Contributor

No description provided.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 58.97436% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.5%. Comparing base (7f020fd) to head (6bb87ec).

Files with missing lines Patch % Lines
django_redis/client/mixins/sorted_sets.py 67.4% 14 Missing and 1 partial ⚠️
django_redis/client/default.py 43.5% 10 Missing and 3 partials ⚠️
django_redis/client/mixins/protocols.py 55.6% 4 Missing ⚠️
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     
Flag Coverage Δ
mypy 44.5% <59.0%> (+6.4%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@terencehonles terencehonles force-pushed the fix-types branch 2 times, most recently from fe662d1 to f2efd69 Compare May 29, 2026 23:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-redis from the typing dependency group and switched to redis.typing types where needed.
  • Narrowed many Redis key parameters from KeyT to str and 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.

Comment thread django_redis/client/mixins/sorted_sets.py
Comment thread django_redis/client/mixins/sorted_sets.py Outdated
Comment thread django_redis/client/mixins/sorted_sets.py Outdated
Comment thread django_redis/client/default.py
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread django_redis/client/mixins/sorted_sets.py
Comment on lines 211 to +227
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,
)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines 211 to +227
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,
)
Comment thread changelog.d/822.bugfix Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@terencehonles terencehonles merged commit 38ec6e4 into jazzband:master May 30, 2026
19 checks passed
@terencehonles terencehonles deleted the fix-types branch May 30, 2026 00:20
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.

2 participants