From 7258a170dc4297cd0c2b972920e6181a4323db22 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 15 Feb 2024 14:52:15 +0200 Subject: [PATCH] Replace black with `ruff format`; run it --- benchmarks/command_packer_benchmark.py | 1 - benchmarks/socket_read_size.py | 1 - redis/client.py | 1 - redis/commands/core.py | 4 +++- redis/commands/graph/commands.py | 4 +--- redis/exceptions.py | 3 +++ tasks.py | 2 +- tests/test_asyncio/test_cluster.py | 11 +++++------ tests/test_asyncio/test_commands.py | 10 +++++----- tests/test_cluster.py | 10 +++++----- tests/test_commands.py | 14 +++++++------- tests/test_connection.py | 1 - 12 files changed, 30 insertions(+), 32 deletions(-) diff --git a/benchmarks/command_packer_benchmark.py b/benchmarks/command_packer_benchmark.py index e66dbbcbf9..4fb7196422 100644 --- a/benchmarks/command_packer_benchmark.py +++ b/benchmarks/command_packer_benchmark.py @@ -78,7 +78,6 @@ def pack_command(self, *args): class CommandPackerBenchmark(Benchmark): - ARGUMENTS = ( { "name": "connection_class", diff --git a/benchmarks/socket_read_size.py b/benchmarks/socket_read_size.py index 544c733178..37ffa97812 100644 --- a/benchmarks/socket_read_size.py +++ b/benchmarks/socket_read_size.py @@ -4,7 +4,6 @@ class SocketReadBenchmark(Benchmark): - ARGUMENTS = ( {"name": "parser", "values": [PythonParser, _HiredisParser]}, { diff --git a/redis/client.py b/redis/client.py index bf3432e7eb..7dbdd14ffa 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1503,7 +1503,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 diff --git a/redis/commands/core.py b/redis/commands/core.py index 8986a48de2..a9fbf5149e 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -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]]], ]: diff --git a/redis/commands/graph/commands.py b/redis/commands/graph/commands.py index d92018f731..1e41a5fb1f 100644 --- a/redis/commands/graph/commands.py +++ b/redis/commands/graph/commands.py @@ -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): diff --git a/redis/exceptions.py b/redis/exceptions.py index dcc06774b0..82f62730ab 100644 --- a/redis/exceptions.py +++ b/redis/exceptions.py @@ -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. @@ -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 diff --git a/tasks.py b/tasks.py index 062905a464..f13c6d7852 100644 --- a/tasks.py +++ b/tasks.py @@ -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") diff --git a/tests/test_asyncio/test_cluster.py b/tests/test_asyncio/test_cluster.py index f3b76b80c9..b512ea7be1 100644 --- a/tests/test_asyncio/test_cluster.py +++ b/tests/test_asyncio/test_cluster.py @@ -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() @@ -1578,7 +1577,7 @@ 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") @@ -1586,7 +1585,7 @@ async def test_cluster_bitop_not(self, r: RedisCluster) -> None: @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") @@ -1594,7 +1593,7 @@ async def test_cluster_bitop_not_in_place(self, r: RedisCluster) -> None: @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") @@ -1605,8 +1604,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") diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index f6ed07fab5..0cc999d145 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -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") @@ -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") @@ -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") @@ -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") diff --git a/tests/test_cluster.py b/tests/test_cluster.py index fe5852d1fb..49992b5789 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1691,7 +1691,7 @@ 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") @@ -1699,7 +1699,7 @@ def test_cluster_bitop_not(self, r): @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") @@ -1707,7 +1707,7 @@ def test_cluster_bitop_not_in_place(self, r): @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") @@ -1718,8 +1718,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") diff --git a/tests/test_commands.py b/tests/test_commands.py index 4cad4c14b6..2687c66bbf 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -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") @@ -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") @@ -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") @@ -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") @@ -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): diff --git a/tests/test_connection.py b/tests/test_connection.py index a58703e3b5..8d79d1460f 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -363,7 +363,6 @@ def test_unix_socket_connection_failure(): class TestUnitConnectionPool: - @pytest.mark.parametrize( "max_conn", (-1, "str"), ids=("non-positive", "wrong type") )