Skip to content

Commit 7b838bb

Browse files
committed
check typing on bloom and cache
1 parent 390360f commit 7b838bb

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

.github/workflows/mypy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
run: |
2828
pip install mypy cryptography pyopenssl requests
2929
pip install types-setuptools
30+
pip install types-cachetools
3031
pip install -r dev_requirements.txt
3132
pip install .[libvalkey]
3233

.mypy.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ ignore_errors = False
3232
ignore_errors = False
3333
[mypy-tests.test_asyncio.test_pubsub]
3434
ignore_errors = False
35+
[mypy-tests.test_cache]
36+
ignore_errors = False
37+
[mypy-tests.test_asyncio.test_cache]
38+
ignore_errors = False
39+
[mypy-tests.test_bloom]
40+
ignore_errors = False
41+
[mypy-tests.test_asyncio.test_bloom]
42+
ignore_errors = False
43+
#[mypy-tests.test_cluster]
44+
#ignore_errors = False
45+
#[mypy-tests.test_asyncio.test_cluster]
46+
#ignore_errors = False
3547

3648
[mypy-benchmarks.*]
3749
ignore_errors = True

tests/test_asyncio/test_bloom.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def intlist(obj):
1616
return [int(v) for v in obj]
1717

1818

19-
async def test_create(decoded_r: valkey.Valkey):
19+
async def test_create(decoded_r: valkey.Valkey[str]):
2020
"""Test CREATE/RESERVE calls"""
2121
assert await decoded_r.bf().create("bloom", 0.01, 1000)
2222
assert await decoded_r.bf().create("bloom_e", 0.01, 1000, expansion=1)
@@ -31,11 +31,11 @@ async def test_create(decoded_r: valkey.Valkey):
3131

3232

3333
@pytest.mark.experimental
34-
async def test_tdigest_create(decoded_r: valkey.Valkey):
34+
async def test_tdigest_create(decoded_r: valkey.Valkey[str]):
3535
assert await decoded_r.tdigest().create("tDigest", 100)
3636

3737

38-
async def test_bf_add(decoded_r: valkey.Valkey):
38+
async def test_bf_add(decoded_r: valkey.Valkey[str]):
3939
assert await decoded_r.bf().create("bloom", 0.01, 1000)
4040
assert 1 == await decoded_r.bf().add("bloom", "foo")
4141
assert 0 == await decoded_r.bf().add("bloom", "foo")
@@ -47,7 +47,7 @@ async def test_bf_add(decoded_r: valkey.Valkey):
4747
assert [1, 0] == intlist(await decoded_r.bf().mexists("bloom", "foo", "noexist"))
4848

4949

50-
async def test_bf_insert(decoded_r: valkey.Valkey):
50+
async def test_bf_insert(decoded_r: valkey.Valkey[str]):
5151
assert await decoded_r.bf().create("bloom", 0.01, 1000)
5252
assert [1] == intlist(await decoded_r.bf().insert("bloom", ["foo"]))
5353
assert [0, 1] == intlist(await decoded_r.bf().insert("bloom", ["foo", "bar"]))
@@ -77,7 +77,7 @@ async def test_bf_insert(decoded_r: valkey.Valkey):
7777
)
7878

7979

80-
async def test_bf_scandump_and_loadchunk(decoded_r: valkey.Valkey):
80+
async def test_bf_scandump_and_loadchunk(decoded_r: valkey.Valkey[str]):
8181
# Store a filter
8282
await decoded_r.bf().create("myBloom", "0.0001", "1000")
8383

@@ -124,7 +124,7 @@ async def do_verify():
124124
await decoded_r.bf().create("myBloom", "0.0001", "10000000")
125125

126126

127-
async def test_bf_info(decoded_r: valkey.Valkey):
127+
async def test_bf_info(decoded_r: valkey.Valkey[str]):
128128
expansion = 4
129129
# Store a filter
130130
await decoded_r.bf().create("nonscaling", "0.0001", "1000", noScale=True)
@@ -155,7 +155,7 @@ async def test_bf_info(decoded_r: valkey.Valkey):
155155
assert True
156156

157157

158-
async def test_bf_card(decoded_r: valkey.Valkey):
158+
async def test_bf_card(decoded_r: valkey.Valkey[str]):
159159
# return 0 if the key does not exist
160160
assert await decoded_r.bf().card("not_exist") == 0
161161

@@ -169,7 +169,7 @@ async def test_bf_card(decoded_r: valkey.Valkey):
169169
await decoded_r.bf().card("setKey")
170170

171171

172-
async def test_cf_add_and_insert(decoded_r: valkey.Valkey):
172+
async def test_cf_add_and_insert(decoded_r: valkey.Valkey[str]):
173173
assert await decoded_r.cf().create("cuckoo", 1000)
174174
assert await decoded_r.cf().add("cuckoo", "filter")
175175
assert not await decoded_r.cf().addnx("cuckoo", "filter")
@@ -194,7 +194,7 @@ async def test_cf_add_and_insert(decoded_r: valkey.Valkey):
194194
)
195195

196196

197-
async def test_cf_exists_and_del(decoded_r: valkey.Valkey):
197+
async def test_cf_exists_and_del(decoded_r: valkey.Valkey[str]):
198198
assert await decoded_r.cf().create("cuckoo", 1000)
199199
assert await decoded_r.cf().add("cuckoo", "filter")
200200
assert await decoded_r.cf().exists("cuckoo", "filter")
@@ -205,7 +205,7 @@ async def test_cf_exists_and_del(decoded_r: valkey.Valkey):
205205
assert 0 == await decoded_r.cf().count("cuckoo", "filter")
206206

207207

208-
async def test_cms(decoded_r: valkey.Valkey):
208+
async def test_cms(decoded_r: valkey.Valkey[str]):
209209
assert await decoded_r.cms().initbydim("dim", 1000, 5)
210210
assert await decoded_r.cms().initbyprob("prob", 0.01, 0.01)
211211
assert await decoded_r.cms().incrby("dim", ["foo"], [5])
@@ -221,7 +221,7 @@ async def test_cms(decoded_r: valkey.Valkey):
221221

222222

223223
@pytest.mark.onlynoncluster
224-
async def test_cms_merge(decoded_r: valkey.Valkey):
224+
async def test_cms_merge(decoded_r: valkey.Valkey[str]):
225225
assert await decoded_r.cms().initbydim("A", 1000, 5)
226226
assert await decoded_r.cms().initbydim("B", 1000, 5)
227227
assert await decoded_r.cms().initbydim("C", 1000, 5)
@@ -237,7 +237,7 @@ async def test_cms_merge(decoded_r: valkey.Valkey):
237237
assert [16, 15, 21] == await decoded_r.cms().query("C", "foo", "bar", "baz")
238238

239239

240-
async def test_topk(decoded_r: valkey.Valkey):
240+
async def test_topk(decoded_r: valkey.Valkey[str]):
241241
# test list with empty buckets
242242
assert await decoded_r.topk().reserve("topk", 3, 50, 4, 0.9)
243243
assert [
@@ -317,7 +317,7 @@ async def test_topk(decoded_r: valkey.Valkey):
317317
assert 0.9 == round(float(info["decay"]), 1)
318318

319319

320-
async def test_topk_incrby(decoded_r: valkey.Valkey):
320+
async def test_topk_incrby(decoded_r: valkey.Valkey[str]):
321321
await decoded_r.flushdb()
322322
assert await decoded_r.topk().reserve("topk", 3, 10, 3, 1)
323323
assert [None, None, None] == await decoded_r.topk().incrby(
@@ -332,7 +332,7 @@ async def test_topk_incrby(decoded_r: valkey.Valkey):
332332

333333

334334
@pytest.mark.experimental
335-
async def test_tdigest_reset(decoded_r: valkey.Valkey):
335+
async def test_tdigest_reset(decoded_r: valkey.Valkey[str]):
336336
assert await decoded_r.tdigest().create("tDigest", 10)
337337
# reset on empty histogram
338338
assert await decoded_r.tdigest().reset("tDigest")
@@ -348,7 +348,7 @@ async def test_tdigest_reset(decoded_r: valkey.Valkey):
348348

349349

350350
@pytest.mark.onlynoncluster
351-
async def test_tdigest_merge(decoded_r: valkey.Valkey):
351+
async def test_tdigest_merge(decoded_r: valkey.Valkey[str]):
352352
assert await decoded_r.tdigest().create("to-tDigest", 10)
353353
assert await decoded_r.tdigest().create("from-tDigest", 10)
354354
# insert data-points into sketch
@@ -375,7 +375,7 @@ async def test_tdigest_merge(decoded_r: valkey.Valkey):
375375

376376

377377
@pytest.mark.experimental
378-
async def test_tdigest_min_and_max(decoded_r: valkey.Valkey):
378+
async def test_tdigest_min_and_max(decoded_r: valkey.Valkey[str]):
379379
assert await decoded_r.tdigest().create("tDigest", 100)
380380
# insert data-points into sketch
381381
assert await decoded_r.tdigest().add("tDigest", [1, 2, 3])
@@ -385,8 +385,8 @@ async def test_tdigest_min_and_max(decoded_r: valkey.Valkey):
385385

386386

387387
@pytest.mark.experimental
388-
@skip_ifmodversion_lt("2.4.0", "bf")
389-
async def test_tdigest_quantile(decoded_r: valkey.Valkey):
388+
@skip_ifmodversion_lt("2.4.0", "bf") # type: ignore[misc]
389+
async def test_tdigest_quantile(decoded_r: valkey.Valkey[str]):
390390
assert await decoded_r.tdigest().create("tDigest", 500)
391391
# insert data-points into sketch
392392
assert await decoded_r.tdigest().add(
@@ -413,7 +413,7 @@ async def test_tdigest_quantile(decoded_r: valkey.Valkey):
413413

414414

415415
@pytest.mark.experimental
416-
async def test_tdigest_cdf(decoded_r: valkey.Valkey):
416+
async def test_tdigest_cdf(decoded_r: valkey.Valkey[str]):
417417
assert await decoded_r.tdigest().create("tDigest", 100)
418418
# insert data-points into sketch
419419
assert await decoded_r.tdigest().add("tDigest", list(range(1, 10)))
@@ -424,8 +424,8 @@ async def test_tdigest_cdf(decoded_r: valkey.Valkey):
424424

425425

426426
@pytest.mark.experimental
427-
@skip_ifmodversion_lt("2.4.0", "bf")
428-
async def test_tdigest_trimmed_mean(decoded_r: valkey.Valkey):
427+
@skip_ifmodversion_lt("2.4.0", "bf") # type: ignore[misc]
428+
async def test_tdigest_trimmed_mean(decoded_r: valkey.Valkey[str]):
429429
assert await decoded_r.tdigest().create("tDigest", 100)
430430
# insert data-points into sketch
431431
assert await decoded_r.tdigest().add("tDigest", list(range(1, 10)))
@@ -434,7 +434,7 @@ async def test_tdigest_trimmed_mean(decoded_r: valkey.Valkey):
434434

435435

436436
@pytest.mark.experimental
437-
async def test_tdigest_rank(decoded_r: valkey.Valkey):
437+
async def test_tdigest_rank(decoded_r: valkey.Valkey[str]):
438438
assert await decoded_r.tdigest().create("t-digest", 500)
439439
assert await decoded_r.tdigest().add("t-digest", list(range(0, 20)))
440440
assert -1 == (await decoded_r.tdigest().rank("t-digest", -1))[0]
@@ -444,7 +444,7 @@ async def test_tdigest_rank(decoded_r: valkey.Valkey):
444444

445445

446446
@pytest.mark.experimental
447-
async def test_tdigest_revrank(decoded_r: valkey.Valkey):
447+
async def test_tdigest_revrank(decoded_r: valkey.Valkey[str]):
448448
assert await decoded_r.tdigest().create("t-digest", 500)
449449
assert await decoded_r.tdigest().add("t-digest", list(range(0, 20)))
450450
assert -1 == (await decoded_r.tdigest().revrank("t-digest", 20))[0]
@@ -453,7 +453,7 @@ async def test_tdigest_revrank(decoded_r: valkey.Valkey):
453453

454454

455455
@pytest.mark.experimental
456-
async def test_tdigest_byrank(decoded_r: valkey.Valkey):
456+
async def test_tdigest_byrank(decoded_r: valkey.Valkey[str]):
457457
assert await decoded_r.tdigest().create("t-digest", 500)
458458
assert await decoded_r.tdigest().add("t-digest", list(range(1, 11)))
459459
assert 1 == (await decoded_r.tdigest().byrank("t-digest", 0))[0]
@@ -464,7 +464,7 @@ async def test_tdigest_byrank(decoded_r: valkey.Valkey):
464464

465465

466466
@pytest.mark.experimental
467-
async def test_tdigest_byrevrank(decoded_r: valkey.Valkey):
467+
async def test_tdigest_byrevrank(decoded_r: valkey.Valkey[str]):
468468
assert await decoded_r.tdigest().create("t-digest", 500)
469469
assert await decoded_r.tdigest().add("t-digest", list(range(1, 11)))
470470
assert 10 == (await decoded_r.tdigest().byrevrank("t-digest", 0))[0]
@@ -474,7 +474,7 @@ async def test_tdigest_byrevrank(decoded_r: valkey.Valkey):
474474
(await decoded_r.tdigest().byrevrank("t-digest", -1))[0]
475475

476476

477-
# # async def test_pipeline(decoded_r: valkey.Valkey):
477+
# # async def test_pipeline(decoded_r: valkey.Valkey[str]):
478478
# pipeline = await decoded_r.bf().pipeline()
479479
# assert not await decoded_r.bf().execute_command("get pipeline")
480480
#

tests/test_cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from tests.conftest import _get_client
99
from valkey import ValkeyError
1010
from valkey._cache import AbstractCache, EvictionPolicy, _LocalCache
11-
from valkey.typing import KeyT, ResponseT
11+
12+
# It is defined, just not in __all__
13+
from valkey.typing import KeyT, ResponseT # type: ignore[attr-defined]
1214
from valkey.utils import LIBVALKEY_AVAILABLE
1315

1416

@@ -529,7 +531,7 @@ def test_cache_decode_response(self, local_cache, sentinel_setup, master):
529531
class TestCustomCache:
530532
class _CustomCache(AbstractCache):
531533
def __init__(self):
532-
self.responses = cachetools.LRUCache(maxsize=1000)
534+
self.responses = cachetools.LRUCache(maxsize=1000) # type: ignore[var-annotated]
533535
self.keys_to_commands = defaultdict(list)
534536
self.commands_to_keys = defaultdict(list)
535537

0 commit comments

Comments
 (0)