Skip to content

Commit 17de472

Browse files
committed
Update redis type annotations
Including working around python/typeshed#6028.
1 parent 64b6d2a commit 17de472

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: django_lightweight_queue/backends/reliable_redis.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,23 @@ def startup(self, queue: QueueName) -> None:
6161
)
6262
processing_queue_keys = current_processing_queue_keys - expected_processing_queue_keys
6363

64-
def move_processing_jobs_to_main(pipe: redis.client.Pipeline) -> None:
64+
def move_processing_jobs_to_main(pipe: 'redis.StrictRedis[bytes]') -> None:
65+
# Note: the `pipe` argument here is actually a Pipeline (strictly
66+
# `redis.client.Pipeline[bytes]`), however it's not the usual
67+
# late-executing pipeline that might be expected (or that the
68+
# typeshed expects) so we pretend that it's a StrictRedis instance
69+
# to get the type checking to *mostly* work. See typeshed issue
70+
# https://github.com/python/typeshed/issues/6028 for more details.
71+
6572
# Collect all the data we need to add, before adding the data back
6673
# to the main queue of and clearing the processing queues
6774
# atomically, so if this crashes, we don't lose jobs
68-
all_data = []
75+
all_data: List[bytes] = []
6976
for key in processing_queue_keys:
7077
all_data.extend(pipe.lrange(key, 0, -1))
7178

7279
if all_data or processing_queue_keys:
73-
pipe.multi()
80+
pipe.multi() # type: ignore[attr-defined] # see https://github.com/python/typeshed/issues/6028
7481

7582
# NB we RPUSH, which means these jobs will get processed next
7683
if all_data:

Diff for: tests/mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class RedisCleanupMixin(object):
5-
client = NotImplemented # type: redis.StrictRedis
5+
client = NotImplemented # type: redis.StrictRedis[bytes]
66
prefix = NotImplemented # type: str
77

88
def setUp(self):

0 commit comments

Comments
 (0)