Skip to content

Commit e9272c7

Browse files
committed
Merge original typing from types-redis, adapt it for valkey.
Signed-off-by: Raphaël Vinot <[email protected]>
1 parent d5bb6bf commit e9272c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+7067
-484
lines changed

.github/workflows/mypy.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Python application
2+
3+
on:
4+
push:
5+
branches: [ types ]
6+
pull_request:
7+
branches: [ types ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python ${{matrix.python-version}}
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{matrix.python-version}}
25+
26+
- name: Install package
27+
run: |
28+
pip install mypy cryptography pyopenssl requests
29+
pip install types-setuptools
30+
pip install types-cachetools
31+
pip install -r dev_requirements.txt
32+
pip install .[libvalkey]
33+
34+
- name: Run MyPy
35+
run: |
36+
mypy --exclude build .

.mypy.ini

+61-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
11
[mypy]
2-
#, docs/examples, tests
3-
files = valkey
4-
check_untyped_defs = True
5-
follow_imports_for_stubs asyncio.= True
6-
#disallow_any_decorated = True
7-
disallow_subclassing_any = True
8-
#disallow_untyped_calls = True
9-
disallow_untyped_decorators = True
10-
#disallow_untyped_defs = True
11-
implicit_reexport = False
12-
no_implicit_optional = True
13-
show_error_codes = True
14-
strict_equality = True
15-
warn_incomplete_stub = True
16-
warn_redundant_casts = True
17-
warn_unreachable = True
18-
warn_unused_ignores = True
19-
disallow_any_unimported = True
20-
#warn_return_any = True
21-
22-
[mypy-valkey.asyncio.lock]
23-
# TODO: Remove once locks has been rewritten
2+
strict = True
3+
show_error_context = True
4+
pretty = True
5+
exclude = docs|build
6+
7+
# These next few are various gradations of forcing use of type annotations
8+
disallow_untyped_calls = False
9+
disallow_incomplete_defs = False
10+
disallow_untyped_defs = False
11+
12+
# This one can be tricky to get passing if you use a lot of untyped libraries
13+
warn_return_any = False
14+
15+
[mypy-valkey._parsers.*]
16+
ignore_errors = True
17+
18+
[mypy-valkey._cache]
19+
ignore_errors = True
20+
21+
[mypy-tests.*]
22+
ignore_errors = True
23+
[mypy-tests.test_bloom]
24+
ignore_errors = False
25+
[mypy-tests.test_asyncio.test_bloom]
26+
ignore_errors = False
27+
[mypy-tests.test_cache]
28+
ignore_errors = False
29+
[mypy-tests.test_asyncio.test_cache]
30+
ignore_errors = False
31+
[mypy-tests.test_commands]
32+
ignore_errors = False
33+
[mypy-tests.test_asyncio.test_commands]
34+
ignore_errors = False
35+
#[mypy-tests.test_cluster]
36+
#ignore_errors = False
37+
#[mypy-tests.test_asyncio.test_cluster]
38+
#ignore_errors = False
39+
#[mypy-tests.test_connection_pool]
40+
#ignore_errors = False
41+
#[mypy-tests.test_asyncio.test_connection_pool]
42+
#ignore_errors = False
43+
#[mypy-tests.test_connection]
44+
#ignore_errors = False
45+
#[mypy-tests.test_asyncio.test_connection]
46+
#ignore_errors = False
47+
[mypy-tests.test_pipeline]
48+
ignore_errors = False
49+
[mypy-tests.test_asyncio.test_pipeline]
50+
ignore_errors = False
51+
[mypy-tests.test_pubsub]
52+
ignore_errors = False
53+
[mypy-tests.test_asyncio.test_pubsub]
54+
ignore_errors = False
55+
56+
[mypy-benchmarks.*]
57+
ignore_errors = True
58+
59+
[mypy-whitelist]
60+
ignore_errors = True
61+
62+
[mypy-tasks]
2463
ignore_errors = True

tests/test_asyncio/compat.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import asyncio
22
from unittest import mock
33

4+
__all__ = ["mock", "aclosing", "create_task"]
5+
46
try:
57
mock.AsyncMock
68
except AttributeError:

tests/test_asyncio/test_bloom.py

+26-26
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
#

0 commit comments

Comments
 (0)