Skip to content

Commit 2d9d6c6

Browse files
committed
Fixed type errors caused by infering JSON values as just object
1 parent 9b2eec6 commit 2d9d6c6

19 files changed

+42
-22
lines changed

tests/commands/json/test_arrappend.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
4+
from typing import List
35

46

57
@pytest.fixture(autouse=True)
68
def setup_json(redis: Redis):
79
json_key = "json_arrappend"
8-
value = {"int": 1, "array": [], "object": {"array": [ 1 ]}}
10+
value: JSONValueT = {"int": 1, "array": [], "object": {"array": [ 1 ]}}
911
redis.json.set(json_key, "$", value)
1012
yield
1113
redis.delete(json_key)
@@ -27,7 +29,7 @@ def test_arrappend_single_element(redis: Redis):
2729
def test_arrappend_multiple_elements(redis: Redis):
2830
key = "json_arrappend"
2931
path = "$.array"
30-
new_values = [1, 'new val', 1.5, True, [1], {"key": "value"}]
32+
new_values: List[JSONValueT] = [1, 'new val', 1.5, True, [1], {"key": "value"}]
3133

3234
assert redis.json.arrappend(key, path, *new_values) == [6]
3335
assert redis.json.get(key, path) == [[1, 'new val', 1.5, True, [1], {"key": "value"}]]

tests/commands/json/test_arrindex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_arrindex"
8-
value = {"array": [1, 'test', ['a'], 1.5, {'test': 1}], "int": 1, "object": {"array": [ 0, 1 ]}}
9+
value: JSONValueT = {"array": [1, 'test', ['a'], 1.5, {'test': 1}], "int": 1, "object": {"array": [ 0, 1 ]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_arrinsert.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_arrinsert"
8-
value = {"int": 1, "array": [], "object": {"array": [0]}}
9+
value: JSONValueT = {"int": 1, "array": [], "object": {"array": [0]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_arrlen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_arrlen"
8-
value = {"array": [1, 2, 3, 4], "int": 1, "object": {"array": [1, 2, 3]}}
9+
value: JSONValueT = {"array": [1, 2, 3, 4], "int": 1, "object": {"array": [1, 2, 3]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_arrpop.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_arrpop"
8-
value = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [5, 6, 7]}}
9+
value: JSONValueT = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [5, 6, 7]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_arrtrim.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_arrtrim"
8-
value = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [5, 6, 7]}}
9+
value: JSONValueT = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [5, 6, 7]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_clear.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_clear"
8-
value = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
9+
value: JSONValueT = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_delete_json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_delete"
8-
value = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
9+
value: JSONValueT = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_forget.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_forget"
8-
value = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
9+
value: JSONValueT = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

tests/commands/json/test_get_json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from upstash_redis import Redis
3+
from upstash_redis.typing import JSONValueT
34

45

56
@pytest.fixture(autouse=True)
67
def setup_json(redis: Redis):
78
json_key = "json_get"
8-
value = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
9+
value: JSONValueT = {"int": 1, "array": [1, 2, 3, 4], "object": {"array": [1, 2, 3]}}
910
redis.json.set(json_key, "$", value)
1011
yield
1112
redis.delete(json_key)

0 commit comments

Comments
 (0)