Skip to content

Commit

Permalink
Replace black with ruff format; run it
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Sep 24, 2024
1 parent bca7242 commit 990604b
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 33 deletions.
1 change: 0 additions & 1 deletion benchmarks/command_packer_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def pack_command(self, *args):


class CommandPackerBenchmark(Benchmark):

ARGUMENTS = (
{
"name": "connection_class",
Expand Down
1 change: 0 additions & 1 deletion benchmarks/socket_read_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class SocketReadBenchmark(Benchmark):

ARGUMENTS = (
{"name": "parser", "values": [PythonParser, _HiredisParser]},
{
Expand Down
1 change: 0 additions & 1 deletion redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,6 @@ def _disconnect_raise_reset(
conn.retry_on_error is None
or isinstance(error, tuple(conn.retry_on_error)) is False
):

self.reset()
raise error

Expand Down
4 changes: 3 additions & 1 deletion redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,9 @@ def smembers(self, name: str) -> Union[Awaitable[Set], Set]:
"""
return self.execute_command("SMEMBERS", name, keys=[name])

def smismember(self, name: str, values: List, *args: List) -> Union[
def smismember(
self, name: str, values: List, *args: List
) -> Union[
Awaitable[List[Union[Literal[0], Literal[1]]]],
List[Union[Literal[0], Literal[1]]],
]:
Expand Down
4 changes: 1 addition & 3 deletions redis/commands/graph/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ def config(self, name, value=None, set=False):
if set:
params.append(value)
else:
raise DataError(
"``value`` can be provided only when ``set`` is True"
) # noqa
raise DataError("``value`` can be provided only when ``set`` is True") # noqa
return self.execute_command(CONFIG_CMD, *params)

def list_keys(self):
Expand Down
3 changes: 3 additions & 0 deletions redis/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ModuleError(ResponseError):

class LockError(RedisError, 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
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def build_docs(c):
def linters(c):
"""Run code linters"""
run("ruff check tests redis")
run("black --target-version py37 --check --diff tests redis")
run("ruff format --check --diff tests redis")
run("vulture redis whitelist.py --min-confidence 80")


Expand Down
1 change: 0 additions & 1 deletion tests/test_asyncio/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ async def test_execute_command_keys_not_provided(self, r):
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
@pytest.mark.onlynoncluster
class TestSentinelLocalCache:

async def test_get_from_cache(self, local_cache, master):
await master.set("foo", "bar")
# get key from redis and save in local cache
Expand Down
11 changes: 5 additions & 6 deletions tests/test_asyncio/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ async def get_mocked_redis_client(
with mock.patch.object(ClusterNode, "execute_command") as execute_command_mock:

async def execute_command(*_args, **_kwargs):

if _args[0] == "CLUSTER SLOTS":
if cluster_slots_raise_error:
raise ResponseError()
Expand Down Expand Up @@ -1580,23 +1579,23 @@ async def test_cluster_bitop_not_empty_string(self, r: RedisCluster) -> None:

@skip_if_server_version_lt("2.6.0")
async def test_cluster_bitop_not(self, r: RedisCluster) -> 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: RedisCluster) -> 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: RedisCluster) -> 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 @@ -1607,8 +1606,8 @@ async def test_cluster_bitop_single_string(self, r: RedisCluster) -> None:

@skip_if_server_version_lt("2.6.0")
async def test_cluster_bitop_string_operands(self, r: RedisCluster) -> 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
10 changes: 5 additions & 5 deletions tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ async def test_bitop_not_empty_string(self, r: redis.Redis):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_not(self, r: redis.Redis):
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 @@ -643,7 +643,7 @@ async def test_bitop_not(self, r: redis.Redis):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_not_in_place(self, r: redis.Redis):
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 @@ -652,7 +652,7 @@ async def test_bitop_not_in_place(self, r: redis.Redis):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_single_string(self, r: redis.Redis):
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 @@ -664,8 +664,8 @@ async def test_bitop_single_string(self, r: redis.Redis):
@skip_if_server_version_lt("2.6.0")
@pytest.mark.onlynoncluster
async def test_bitop_string_operands(self, r: redis.Redis):
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
1 change: 0 additions & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ def test_execute_command_keys_not_provided(self, r):
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
@pytest.mark.onlynoncluster
class TestSentinelLocalCache:

def test_get_from_cache(self, local_cache, master):
master.set("foo", "bar")
# get key from redis and save in local cache
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,23 +1694,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 @@ -1721,8 +1721,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
14 changes: 7 additions & 7 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,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 @@ -1049,7 +1049,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 @@ -1058,7 +1058,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 @@ -1070,8 +1070,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 Expand Up @@ -3214,8 +3214,8 @@ def test_hmget(self, r):
def test_hmset(self, r):
redis_class = type(r).__name__
warning_message = (
r"^{0}\.hmset\(\) is deprecated\. "
r"Use {0}\.hset\(\) instead\.$".format(redis_class)
rf"^{redis_class}\.hmset\(\) is deprecated\. "
rf"Use {redis_class}\.hset\(\) instead\.$"
)
h = {b"a": b"1", b"b": b"2", b"c": b"3"}
with pytest.warns(DeprecationWarning, match=warning_message):
Expand Down

0 comments on commit 990604b

Please sign in to comment.