Skip to content

Commit 233dde2

Browse files
committed
Replace black with ruff format; run it
1 parent 7842831 commit 233dde2

31 files changed

+77
-83
lines changed

Diff for: benchmarks/basic_operations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def wrapper(*args, **kwargs):
5454
count = args[1]
5555
print(f"{func.__name__} - {count} Requests")
5656
print(f"Duration = {duration}")
57-
print(f"Rate = {count/duration}")
57+
print(f"Rate = {count / duration}")
5858
print()
5959
return ret
6060

Diff for: benchmarks/command_packer_benchmark.py

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def pack_command(self, *args):
7878

7979

8080
class CommandPackerBenchmark(Benchmark):
81-
8281
ARGUMENTS = (
8382
{
8483
"name": "connection_class",

Diff for: benchmarks/socket_read_size.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class SocketReadBenchmark(Benchmark):
7-
87
ARGUMENTS = (
98
{"name": "parser", "values": [PythonParser, _HiredisParser]},
109
{

Diff for: redis/_parsers/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
from .encoders import Encoder
3333
from .socket import SERVER_CLOSED_CONNECTION_ERROR, SocketBuffer
3434

35-
MODULE_LOAD_ERROR = "Error loading the extension. " "Please check the server logs."
35+
MODULE_LOAD_ERROR = "Error loading the extension. Please check the server logs."
3636
NO_SUCH_MODULE_ERROR = "Error unloading module: no such module with that name"
37-
MODULE_UNLOAD_NOT_POSSIBLE_ERROR = "Error unloading module: operation not " "possible."
37+
MODULE_UNLOAD_NOT_POSSIBLE_ERROR = "Error unloading module: operation not possible."
3838
MODULE_EXPORTS_DATA_TYPES_ERROR = (
3939
"Error unloading module: the module "
4040
"exports one or more module-side data "

Diff for: redis/asyncio/cluster.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,7 @@ def get_node(
11541154
return self.nodes_cache.get(node_name)
11551155
else:
11561156
raise DataError(
1157-
"get_node requires one of the following: "
1158-
"1. node name "
1159-
"2. host and port"
1157+
"get_node requires one of the following: 1. node name 2. host and port"
11601158
)
11611159

11621160
def set_nodes(
@@ -1338,7 +1336,7 @@ async def initialize(self) -> None:
13381336
if len(disagreements) > 5:
13391337
raise RedisClusterException(
13401338
f"startup_nodes could not agree on a valid "
1341-
f'slots cache: {", ".join(disagreements)}'
1339+
f"slots cache: {', '.join(disagreements)}"
13421340
)
13431341

13441342
# Validate if all slots are covered or if we should try next startup node

Diff for: redis/auth/token.py

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def get_received_at_ms(self) -> float:
7777

7878

7979
class JWToken(TokenInterface):
80-
8180
REQUIRED_FIELDS = {"exp"}
8281

8382
def __init__(self, token: str):

Diff for: redis/client.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,7 @@ def raise_first_error(self, commands, response):
15141514
def annotate_exception(self, exception, number, command):
15151515
cmd = " ".join(map(safe_str, command))
15161516
msg = (
1517-
f"Command # {number} ({cmd}) of pipeline "
1518-
f"caused error: {exception.args[0]}"
1517+
f"Command # {number} ({cmd}) of pipeline caused error: {exception.args[0]}"
15191518
)
15201519
exception.args = (msg,) + exception.args[1:]
15211520

Diff for: redis/cluster.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ def initialize(self):
16281628
if len(disagreements) > 5:
16291629
raise RedisClusterException(
16301630
f"startup_nodes could not agree on a valid "
1631-
f'slots cache: {", ".join(disagreements)}'
1631+
f"slots cache: {', '.join(disagreements)}"
16321632
)
16331633

16341634
fully_covered = self.check_slots_coverage(tmp_slots)
@@ -2047,8 +2047,7 @@ def annotate_exception(self, exception, number, command):
20472047
"""
20482048
cmd = " ".join(map(safe_str, command))
20492049
msg = (
2050-
f"Command # {number} ({cmd}) of pipeline "
2051-
f"caused error: {exception.args[0]}"
2050+
f"Command # {number} ({cmd}) of pipeline caused error: {exception.args[0]}"
20522051
)
20532052
exception.args = (msg,) + exception.args[1:]
20542053

Diff for: redis/commands/cluster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def cluster_setslot(
595595
"CLUSTER SETSLOT", slot_id, state, node_id, target_nodes=target_node
596596
)
597597
elif state.upper() == "STABLE":
598-
raise RedisError('For "stable" state please use ' "cluster_setslot_stable")
598+
raise RedisError('For "stable" state please use cluster_setslot_stable')
599599
else:
600600
raise RedisError(f"Invalid slot state: {state}")
601601

Diff for: redis/commands/core.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3413,7 +3413,9 @@ def smembers(self, name: str) -> Union[Awaitable[Set], Set]:
34133413
"""
34143414
return self.execute_command("SMEMBERS", name, keys=[name])
34153415

3416-
def smismember(self, name: str, values: List, *args: List) -> Union[
3416+
def smismember(
3417+
self, name: str, values: List, *args: List
3418+
) -> Union[
34173419
Awaitable[List[Union[Literal[0], Literal[1]]]],
34183420
List[Union[Literal[0], Literal[1]]],
34193421
]:
@@ -4160,8 +4162,7 @@ def zadd(
41604162
raise DataError("ZADD allows either 'gt' or 'lt', not both")
41614163
if incr and len(mapping) != 1:
41624164
raise DataError(
4163-
"ZADD option 'incr' only works when passing a "
4164-
"single element/score pair"
4165+
"ZADD option 'incr' only works when passing a single element/score pair"
41654166
)
41664167
if nx and (gt or lt):
41674168
raise DataError("Only one of 'nx', 'lt', or 'gr' may be defined.")

Diff for: redis/commands/graph/commands.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ def config(self, name, value=None, set=False):
171171
if set:
172172
params.append(value)
173173
else:
174-
raise DataError(
175-
"``value`` can be provided only when ``set`` is True"
176-
) # noqa
174+
raise DataError("``value`` can be provided only when ``set`` is True") # noqa
177175
return self.execute_command(CONFIG_CMD, *params)
178176

179177
def list_keys(self):

Diff for: redis/commands/helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def stringify_param_value(value):
138138
elif value is None:
139139
return "null"
140140
elif isinstance(value, (list, tuple)):
141-
return f'[{",".join(map(stringify_param_value, value))}]'
141+
return f"[{','.join(map(stringify_param_value, value))}]"
142142
elif isinstance(value, dict):
143-
return f'{{{",".join(f"{k}:{stringify_param_value(v)}" for k, v in value.items())}}}' # noqa
143+
return f"{{{','.join(f'{k}:{stringify_param_value(v)}' for k, v in value.items())}}}" # noqa
144144
else:
145145
return str(value)
146146

Diff for: redis/connection.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ def read_response(
618618
except OSError as e:
619619
if disconnect_on_error:
620620
self.disconnect()
621-
raise ConnectionError(
622-
f"Error while reading from {host_error}" f" : {e.args}"
623-
)
621+
raise ConnectionError(f"Error while reading from {host_error} : {e.args}")
624622
except BaseException:
625623
# Also by default close in case of BaseException. A lot of code
626624
# relies on this behaviour when doing Command/Response pairs.

Diff for: redis/exceptions.py

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class ModuleError(ResponseError):
7979

8080
class LockError(RedisError, ValueError):
8181
"Errors acquiring or releasing a lock"
82+
8283
# NOTE: For backwards compatibility, this class derives from ValueError.
8384
# This was originally chosen to behave like threading.Lock.
8485

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

9091
class LockNotOwnedError(LockError):
9192
"Error trying to extend or release a lock that is (no longer) owned"
93+
9294
pass
9395

9496

9597
class ChildDeadlockedError(Exception):
9698
"Error indicating that a child process is deadlocked after a fork()"
99+
97100
pass
98101

99102

Diff for: redis/ocsp.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _check_certificate(issuer_cert, ocsp_bytes, validate=True):
5757
if ocsp_response.response_status == ocsp.OCSPResponseStatus.SUCCESSFUL:
5858
if ocsp_response.certificate_status != ocsp.OCSPCertStatus.GOOD:
5959
raise ConnectionError(
60-
f'Received an {str(ocsp_response.certificate_status).split(".")[1]} '
60+
f"Received an {str(ocsp_response.certificate_status).split('.')[1]} "
6161
"ocsp certificate status"
6262
)
6363
else:

Diff for: redis/sentinel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def __repr__(self):
273273
)
274274
return (
275275
f"<{type(self).__module__}.{type(self).__name__}"
276-
f'(sentinels=[{",".join(sentinel_addresses)}])>'
276+
f"(sentinels=[{','.join(sentinel_addresses)}])>"
277277
)
278278

279279
def check_master_state(self, state, service_name):

Diff for: tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def build_docs(c):
2828
def linters(c):
2929
"""Run code linters"""
3030
run("ruff check tests redis")
31-
run("black --target-version py37 --check --diff tests redis")
31+
run("ruff format --check --diff tests redis")
3232
run("vulture redis whitelist.py --min-confidence 80")
3333

3434

Diff for: tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def wait_for_command(client, monitor, command, key=None):
775775
if Version(redis_version) >= Version("5.0.0"):
776776
id_str = str(client.client_id())
777777
else:
778-
id_str = f"{random.randrange(2 ** 32):08x}"
778+
id_str = f"{random.randrange(2**32):08x}"
779779
key = f"__REDIS-PY-{id_str}__"
780780
client.get(key)
781781
while True:

Diff for: tests/test_asyncio/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ async def wait_for_command(
392392
if Version(redis_version) >= Version("5.0.0"):
393393
id_str = str(await client.client_id())
394394
else:
395-
id_str = f"{random.randrange(2 ** 32):08x}"
395+
id_str = f"{random.randrange(2**32):08x}"
396396
key = f"__REDIS-PY-{id_str}__"
397397
await client.get(key)
398398
while True:

Diff for: tests/test_asyncio/test_cluster.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ async def get_mocked_redis_client(
146146
with mock.patch.object(ClusterNode, "execute_command") as execute_command_mock:
147147

148148
async def execute_command(*_args, **_kwargs):
149-
150149
if _args[0] == "CLUSTER SLOTS":
151150
if cluster_slots_raise_error:
152151
raise ResponseError()
@@ -1577,23 +1576,23 @@ async def test_cluster_bitop_not_empty_string(self, r: RedisCluster) -> None:
15771576

15781577
@skip_if_server_version_lt("2.6.0")
15791578
async def test_cluster_bitop_not(self, r: RedisCluster) -> None:
1580-
test_str = b"\xAA\x00\xFF\x55"
1579+
test_str = b"\xaa\x00\xff\x55"
15811580
correct = ~0xAA00FF55 & 0xFFFFFFFF
15821581
await r.set("{foo}a", test_str)
15831582
await r.bitop("not", "{foo}r", "{foo}a")
15841583
assert int(binascii.hexlify(await r.get("{foo}r")), 16) == correct
15851584

15861585
@skip_if_server_version_lt("2.6.0")
15871586
async def test_cluster_bitop_not_in_place(self, r: RedisCluster) -> None:
1588-
test_str = b"\xAA\x00\xFF\x55"
1587+
test_str = b"\xaa\x00\xff\x55"
15891588
correct = ~0xAA00FF55 & 0xFFFFFFFF
15901589
await r.set("{foo}a", test_str)
15911590
await r.bitop("not", "{foo}a", "{foo}a")
15921591
assert int(binascii.hexlify(await r.get("{foo}a")), 16) == correct
15931592

15941593
@skip_if_server_version_lt("2.6.0")
15951594
async def test_cluster_bitop_single_string(self, r: RedisCluster) -> None:
1596-
test_str = b"\x01\x02\xFF"
1595+
test_str = b"\x01\x02\xff"
15971596
await r.set("{foo}a", test_str)
15981597
await r.bitop("and", "{foo}res1", "{foo}a")
15991598
await r.bitop("or", "{foo}res2", "{foo}a")
@@ -1604,8 +1603,8 @@ async def test_cluster_bitop_single_string(self, r: RedisCluster) -> None:
16041603

16051604
@skip_if_server_version_lt("2.6.0")
16061605
async def test_cluster_bitop_string_operands(self, r: RedisCluster) -> None:
1607-
await r.set("{foo}a", b"\x01\x02\xFF\xFF")
1608-
await r.set("{foo}b", b"\x01\x02\xFF")
1606+
await r.set("{foo}a", b"\x01\x02\xff\xff")
1607+
await r.set("{foo}b", b"\x01\x02\xff")
16091608
await r.bitop("and", "{foo}res1", "{foo}a", "{foo}b")
16101609
await r.bitop("or", "{foo}res2", "{foo}a", "{foo}b")
16111610
await r.bitop("xor", "{foo}res3", "{foo}a", "{foo}b")

Diff for: tests/test_asyncio/test_commands.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,9 @@ async def test_config_set_for_search_module(self, r: redis.Redis):
711711
"search-default-dialect"
712712
] == default_dialect_new
713713
assert (
714-
(await r.ft().config_get("*"))[b"DEFAULT_DIALECT"]
715-
).decode() == default_dialect_new
714+
((await r.ft().config_get("*"))[b"DEFAULT_DIALECT"]).decode()
715+
== default_dialect_new
716+
)
716717
except AssertionError as ex:
717718
raise ex
718719
finally:
@@ -844,7 +845,7 @@ async def test_bitop_not_empty_string(self, r: redis.Redis):
844845
@skip_if_server_version_lt("2.6.0")
845846
@pytest.mark.onlynoncluster
846847
async def test_bitop_not(self, r: redis.Redis):
847-
test_str = b"\xAA\x00\xFF\x55"
848+
test_str = b"\xaa\x00\xff\x55"
848849
correct = ~0xAA00FF55 & 0xFFFFFFFF
849850
await r.set("a", test_str)
850851
await r.bitop("not", "r", "a")
@@ -853,7 +854,7 @@ async def test_bitop_not(self, r: redis.Redis):
853854
@skip_if_server_version_lt("2.6.0")
854855
@pytest.mark.onlynoncluster
855856
async def test_bitop_not_in_place(self, r: redis.Redis):
856-
test_str = b"\xAA\x00\xFF\x55"
857+
test_str = b"\xaa\x00\xff\x55"
857858
correct = ~0xAA00FF55 & 0xFFFFFFFF
858859
await r.set("a", test_str)
859860
await r.bitop("not", "a", "a")
@@ -862,7 +863,7 @@ async def test_bitop_not_in_place(self, r: redis.Redis):
862863
@skip_if_server_version_lt("2.6.0")
863864
@pytest.mark.onlynoncluster
864865
async def test_bitop_single_string(self, r: redis.Redis):
865-
test_str = b"\x01\x02\xFF"
866+
test_str = b"\x01\x02\xff"
866867
await r.set("a", test_str)
867868
await r.bitop("and", "res1", "a")
868869
await r.bitop("or", "res2", "a")
@@ -874,8 +875,8 @@ async def test_bitop_single_string(self, r: redis.Redis):
874875
@skip_if_server_version_lt("2.6.0")
875876
@pytest.mark.onlynoncluster
876877
async def test_bitop_string_operands(self, r: redis.Redis):
877-
await r.set("a", b"\x01\x02\xFF\xFF")
878-
await r.set("b", b"\x01\x02\xFF")
878+
await r.set("a", b"\x01\x02\xff\xff")
879+
await r.set("b", b"\x01\x02\xff")
879880
await r.bitop("and", "res1", "a", "b")
880881
await r.bitop("or", "res2", "a", "b")
881882
await r.bitop("xor", "res3", "a", "b")

Diff for: tests/test_asyncio/test_graph.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ async def test_graph_creation(decoded_r: redis.Redis):
4444
await graph.commit()
4545

4646
query = (
47-
'MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country) '
48-
"RETURN p, v, c"
47+
'MATCH (p:person)-[v:visited {purpose:"pleasure"}]->(c:country) RETURN p, v, c'
4948
)
5049

5150
result = await graph.query(query)

Diff for: tests/test_asyncio/test_pubsub.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,11 @@ async def get_msg():
10501050
assert msg is not None
10511051
# timeout waiting for another message which never arrives
10521052
assert pubsub.connection.is_connected
1053-
with patch("redis._parsers._AsyncRESP2Parser.read_response") as mock1, patch(
1054-
"redis._parsers._AsyncHiredisParser.read_response"
1055-
) as mock2, patch("redis._parsers._AsyncRESP3Parser.read_response") as mock3:
1053+
with (
1054+
patch("redis._parsers._AsyncRESP2Parser.read_response") as mock1,
1055+
patch("redis._parsers._AsyncHiredisParser.read_response") as mock2,
1056+
patch("redis._parsers._AsyncRESP3Parser.read_response") as mock3,
1057+
):
10561058
mock1.side_effect = BaseException("boom")
10571059
mock2.side_effect = BaseException("boom")
10581060
mock3.side_effect = BaseException("boom")

Diff for: tests/test_asyncio/test_search.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1797,10 +1797,10 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17971797
docs[0]["vector_emb"], dtype=np.float32
17981798
)
17991799

1800-
assert np.array_equal(
1801-
decoded_vec_from_search_results, fake_vec
1802-
), "The vectors are not equal"
1800+
assert np.array_equal(decoded_vec_from_search_results, fake_vec), (
1801+
"The vectors are not equal"
1802+
)
18031803

1804-
assert (
1805-
docs[0]["first_name"] == mixed_data["first_name"]
1806-
), "The text field is not decoded correctly"
1804+
assert docs[0]["first_name"] == mixed_data["first_name"], (
1805+
"The text field is not decoded correctly"
1806+
)

Diff for: tests/test_auth/test_token.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class TestToken:
10-
1110
def test_simple_token(self):
1211
token = SimpleToken(
1312
"value",

0 commit comments

Comments
 (0)