Skip to content

Fix updated linters errors #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def skip_ifmodversion_lt(min_version: str, module_name: str):
if module_name == j.get("name"):
version = j.get("ver")
mv = int(
"".join(["%02d" % int(segment) for segment in min_version.split(".")])
"".join([f"{int(segment):02}" for segment in min_version.split(".")])
)
check = version < mv
return pytest.mark.skipif(check, reason="Valkey module version")
Expand Down
19 changes: 12 additions & 7 deletions tests/test_asyncio/test_cluster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import binascii
import datetime
import math
import ssl
import warnings
from typing import Any, Awaitable, Callable, Dict, List, Optional, Type, Union
Expand Down Expand Up @@ -1556,23 +1557,23 @@ async def test_cluster_bitop_not_empty_string(self, r: ValkeyCluster) -> None:

@skip_if_server_version_lt("2.6.0")
async def test_cluster_bitop_not(self, r: ValkeyCluster) -> None:
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
await r.set("{foo}a", test_str)
await r.bitop("not", "{foo}r", "{foo}a")
assert int(binascii.hexlify(await r.get("{foo}r")), 16) == correct

@skip_if_server_version_lt("2.6.0")
async def test_cluster_bitop_not_in_place(self, r: ValkeyCluster) -> None:
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
await r.set("{foo}a", test_str)
await r.bitop("not", "{foo}a", "{foo}a")
assert int(binascii.hexlify(await r.get("{foo}a")), 16) == correct

@skip_if_server_version_lt("2.6.0")
async def test_cluster_bitop_single_string(self, r: ValkeyCluster) -> None:
test_str = b"\x01\x02\xFF"
test_str = b"\x01\x02\xff"
await r.set("{foo}a", test_str)
await r.bitop("and", "{foo}res1", "{foo}a")
await r.bitop("or", "{foo}res2", "{foo}a")
Expand All @@ -1583,8 +1584,8 @@ async def test_cluster_bitop_single_string(self, r: ValkeyCluster) -> None:

@skip_if_server_version_lt("2.6.0")
async def test_cluster_bitop_string_operands(self, r: ValkeyCluster) -> None:
await r.set("{foo}a", b"\x01\x02\xFF\xFF")
await r.set("{foo}b", b"\x01\x02\xFF")
await r.set("{foo}a", b"\x01\x02\xff\xff")
await r.set("{foo}b", b"\x01\x02\xff")
await r.bitop("and", "{foo}res1", "{foo}a", "{foo}b")
await r.bitop("or", "{foo}res2", "{foo}a", "{foo}b")
await r.bitop("xor", "{foo}res3", "{foo}a", "{foo}b")
Expand Down Expand Up @@ -2158,7 +2159,9 @@ async def test_geosearchstore_dist(self, r: ValkeyCluster) -> None:
storedist=True,
)
# instead of save the geo score, the distance is saved.
assert await r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301
E = 1e-9
res = await r.zscore("{foo}places_barcelona", "place1")
assert math.fabs(res - 88.05060698409301) < E

@skip_if_server_version_lt("3.2.0")
async def test_cluster_georadius_store(self, r: ValkeyCluster) -> None:
Expand Down Expand Up @@ -2188,7 +2191,9 @@ async def test_cluster_georadius_store_dist(self, r: ValkeyCluster) -> None:
"{foo}barcelona", 2.191, 41.433, 1000, store_dist="{foo}places_barcelona"
)
# instead of save the geo score, the distance is saved.
assert await r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301
E = 1e-9
res = await r.zscore("{foo}places_barcelona", "place1")
assert math.fabs(res - 88.05060698409301) < E

async def test_cluster_dbsize(self, r: ValkeyCluster) -> None:
d = {"a": b"1", "b": b"2", "c": b"3", "d": b"4"}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ async def test_bitop_not_empty_string(self, r: valkey.Valkey):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_not(self, r: valkey.Valkey):
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
await r.set("a", test_str)
await r.bitop("not", "r", "a")
Expand All @@ -648,7 +648,7 @@ async def test_bitop_not(self, r: valkey.Valkey):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_not_in_place(self, r: valkey.Valkey):
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
await r.set("a", test_str)
await r.bitop("not", "a", "a")
Expand All @@ -657,7 +657,7 @@ async def test_bitop_not_in_place(self, r: valkey.Valkey):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_single_string(self, r: valkey.Valkey):
test_str = b"\x01\x02\xFF"
test_str = b"\x01\x02\xff"
await r.set("a", test_str)
await r.bitop("and", "res1", "a")
await r.bitop("or", "res2", "a")
Expand All @@ -669,8 +669,8 @@ async def test_bitop_single_string(self, r: valkey.Valkey):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_string_operands(self, r: valkey.Valkey):
await r.set("a", b"\x01\x02\xFF\xFF")
await r.set("b", b"\x01\x02\xFF")
await r.set("a", b"\x01\x02\xff\xff")
await r.set("b", b"\x01\x02\xff")
await r.bitop("and", "res1", "a", "b")
await r.bitop("or", "res2", "a", "b")
await r.bitop("xor", "res3", "a", "b")
Expand Down
23 changes: 16 additions & 7 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import binascii
import datetime
import math
import select
import socket
import socketserver
Expand Down Expand Up @@ -1663,23 +1664,23 @@ def test_cluster_bitop_not_empty_string(self, r):

@skip_if_server_version_lt("2.6.0")
def test_cluster_bitop_not(self, r):
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
r["{foo}a"] = test_str
r.bitop("not", "{foo}r", "{foo}a")
assert int(binascii.hexlify(r["{foo}r"]), 16) == correct

@skip_if_server_version_lt("2.6.0")
def test_cluster_bitop_not_in_place(self, r):
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
r["{foo}a"] = test_str
r.bitop("not", "{foo}a", "{foo}a")
assert int(binascii.hexlify(r["{foo}a"]), 16) == correct

@skip_if_server_version_lt("2.6.0")
def test_cluster_bitop_single_string(self, r):
test_str = b"\x01\x02\xFF"
test_str = b"\x01\x02\xff"
r["{foo}a"] = test_str
r.bitop("and", "{foo}res1", "{foo}a")
r.bitop("or", "{foo}res2", "{foo}a")
Expand All @@ -1690,8 +1691,8 @@ def test_cluster_bitop_single_string(self, r):

@skip_if_server_version_lt("2.6.0")
def test_cluster_bitop_string_operands(self, r):
r["{foo}a"] = b"\x01\x02\xFF\xFF"
r["{foo}b"] = b"\x01\x02\xFF"
r["{foo}a"] = b"\x01\x02\xff\xff"
r["{foo}b"] = b"\x01\x02\xff"
r.bitop("and", "{foo}res1", "{foo}a", "{foo}b")
r.bitop("or", "{foo}res2", "{foo}a", "{foo}b")
r.bitop("xor", "{foo}res3", "{foo}a", "{foo}b")
Expand Down Expand Up @@ -2247,7 +2248,11 @@ def test_geosearchstore_dist(self, r):
storedist=True,
)
# instead of save the geo score, the distance is saved.
assert r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301
E = 1e-9
assert (
math.fabs(r.zscore("{foo}places_barcelona", "place1") - 88.05060698409301)
< E
)

@skip_if_server_version_lt("3.2.0")
def test_cluster_georadius_store(self, r):
Expand Down Expand Up @@ -2277,7 +2282,11 @@ def test_cluster_georadius_store_dist(self, r):
"{foo}barcelona", 2.191, 41.433, 1000, store_dist="{foo}places_barcelona"
)
# instead of save the geo score, the distance is saved.
assert r.zscore("{foo}places_barcelona", "place1") == 88.05060698409301
E = 1e-9
assert (
math.fabs(r.zscore("{foo}places_barcelona", "place1") - 88.05060698409301)
< E
)

def test_cluster_dbsize(self, r):
d = {"a": b"1", "b": b"2", "c": b"3", "d": b"4"}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ def test_bitop_not_empty_string(self, r):
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.6.0")
def test_bitop_not(self, r):
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
r["a"] = test_str
r.bitop("not", "r", "a")
Expand All @@ -1024,7 +1024,7 @@ def test_bitop_not(self, r):
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.6.0")
def test_bitop_not_in_place(self, r):
test_str = b"\xAA\x00\xFF\x55"
test_str = b"\xaa\x00\xff\x55"
correct = ~0xAA00FF55 & 0xFFFFFFFF
r["a"] = test_str
r.bitop("not", "a", "a")
Expand All @@ -1033,7 +1033,7 @@ def test_bitop_not_in_place(self, r):
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.6.0")
def test_bitop_single_string(self, r):
test_str = b"\x01\x02\xFF"
test_str = b"\x01\x02\xff"
r["a"] = test_str
r.bitop("and", "res1", "a")
r.bitop("or", "res2", "a")
Expand All @@ -1045,8 +1045,8 @@ def test_bitop_single_string(self, r):
@pytest.mark.onlynoncluster
@skip_if_server_version_lt("2.6.0")
def test_bitop_string_operands(self, r):
r["a"] = b"\x01\x02\xFF\xFF"
r["b"] = b"\x01\x02\xFF"
r["a"] = b"\x01\x02\xff\xff"
r["b"] = b"\x01\x02\xff"
r.bitop("and", "res1", "a", "b")
r.bitop("or", "res2", "a", "b")
r.bitop("xor", "res3", "a", "b")
Expand Down
3 changes: 1 addition & 2 deletions valkey/_parsers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ def parse_stralgo(response, **options):
if options.get("idx", False):
if options.get("withmatchlen", False):
matches = [
[(int(match[-1]))] + list(map(tuple, match[:-1]))
for match in response[1]
[int(match[-1])] + list(map(tuple, match[:-1])) for match in response[1]
]
else:
matches = [list(map(tuple, match)) for match in response[1]]
Expand Down
4 changes: 3 additions & 1 deletion valkey/_parsers/url_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from typing import Callable, Mapping, Optional
from urllib.parse import ParseResult, parse_qs, unquote, urlparse

from valkey.asyncio.connection import ConnectKwargs
from valkey.asyncio.connection import (
ConnectKwargs,
)
from valkey.asyncio.connection import SSLConnection as SSLConnectionAsync
from valkey.asyncio.connection import (
UnixDomainSocketConnection as UnixDomainSocketConnectionAsync,
Expand Down
3 changes: 3 additions & 0 deletions valkey/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ModuleError(ResponseError):

class LockError(ValkeyError, ValueError):
"Errors acquiring or releasing a lock"

# NOTE: For backwards compatibility, this class derives from ValueError.
# This was originally chosen to behave like threading.Lock.

Expand All @@ -89,11 +90,13 @@ def __init__(self, message=None, lock_name=None):

class LockNotOwnedError(LockError):
"Error trying to extend or release a lock that is (no longer) owned"

pass


class ChildDeadlockedError(Exception):
"Error indicating that a child process is deadlocked after a fork()"

pass


Expand Down
Loading