Add Ruff linter and fix lint issues

This commit is contained in:
Julien Letessier 2026-01-15 11:07:36 +01:00
parent 8b8b3ff32a
commit eb52fdd202
14 changed files with 45 additions and 26 deletions

View File

@ -5,4 +5,5 @@ description = "A high performance and fully featured proxy for redis sentinel an
requires-python = ">=3.8,<3.14"
dependencies = [
"redis>=5.0.0,<8.0.0",
"ruff>=0.5.0",
]

View File

@ -6,7 +6,6 @@
#
import time
import sys
import argparse
from test_util import get_host_port, make_client, exit_with_result

View File

@ -3,7 +3,6 @@
# Verify EVAL/EVALSHA rejects multi-key cross-shard scripts
#
import sys
from test_util import parse_args, make_client, exit_with_result

View File

@ -3,7 +3,6 @@
# Verify MGET returns WRONGTYPE for non-string keys
#
import sys
from test_util import parse_args, make_client, exit_with_result

View File

@ -3,7 +3,6 @@
# Verify MSETNX does not partially apply changes when it returns 0
#
import sys
from test_util import parse_args, make_client, exit_with_result
@ -14,7 +13,7 @@ def run_test(host, port):
try:
r = c.execute_command("MSETNX", "msetnx_k1", "v1", "msetnx_k2", "v2")
except Exception as exc:
except Exception:
# If proxy rejects cross-shard MSETNX, this is acceptable.
return True

View File

@ -4,8 +4,6 @@
#
import socket
import sys
import time
from test_util import parse_args, make_client, exit_with_result

View File

@ -27,23 +27,23 @@ def test():
[ps, 'psubscribe', ['ch*']],
[ps, 'get_message', [], {'pattern': None, 'type': 'psubscribe', 'channel': 'ch*', 'data': 4}],
[c2, 'publish', ['ch', 'hello'], 2],
[ps, 'get_message', [], lambda x:type(x)==type({}) and (x.get('data') == 'hello' or (isinstance(x.get('data'), bytes) and x.get('data').decode('utf-8') == 'hello'))],
[ps, 'get_message', [], lambda x:type(x)==type({}) and (x.get('data') == 'hello' or (isinstance(x.get('data'), bytes) and x.get('data').decode('utf-8') == 'hello'))],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and (x.get('data') == 'hello' or (isinstance(x.get('data'), bytes) and x.get('data').decode('utf-8') == 'hello'))],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and (x.get('data') == 'hello' or (isinstance(x.get('data'), bytes) and x.get('data').decode('utf-8') == 'hello'))],
[ps, 'psubscribe', ['ch1*', 'ch2*']],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='psubscribe'],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='psubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='psubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='psubscribe'],
[ps, 'unsubscribe', ['ch']],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='unsubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='unsubscribe'],
[c2, 'publish', ['ch', 'hello'], 1],
[ps, 'get_message', [], lambda x:type(x)==type({}) and (x.get('data') == 'hello' or (isinstance(x.get('data'), bytes) and x.get('data').decode('utf-8') == 'hello'))],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and (x.get('data') == 'hello' or (isinstance(x.get('data'), bytes) and x.get('data').decode('utf-8') == 'hello'))],
[ps, 'punsubscribe', ['ch*']],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='punsubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='punsubscribe'],
[ps, 'unsubscribe', ['ch1', 'ch2']],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='unsubscribe'],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='unsubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='unsubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='unsubscribe'],
[ps, 'punsubscribe', ['ch1*', 'ch2*']],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='punsubscribe'],
[ps, 'get_message', [], lambda x:type(x)==type({}) and x['type']=='punsubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='punsubscribe'],
[ps, 'get_message', [], lambda x:isinstance(x, dict) and x['type']=='punsubscribe'],
]
def normalize_value(v):
"""Convert byte strings to strings for comparison."""

View File

@ -3,7 +3,6 @@
# Verify subscribe/psubscribe confirmation with long channel/pattern names
#
import sys
from test_util import parse_args, make_client, exit_with_result

View File

@ -3,7 +3,6 @@
# Verify pubsub message responses include message data
#
import sys
from test_util import parse_args, make_clients, exit_with_result

View File

@ -70,7 +70,7 @@ def test_redis(host, port):
return False
else:
print(f" ✗ Expected psubscribe confirmation, got: {msg}")
print(f" This is the bug: old messages are returned instead of new ones")
print(" This is the bug: old messages are returned instead of new ones")
return False
if __name__ == '__main__':

View File

@ -3,7 +3,6 @@
# Verify pubsub parser state does not reuse old messages
#
import sys
from test_util import parse_args, make_clients, exit_with_result

View File

@ -3,9 +3,7 @@
# Verify subscription confirmations arrive before messages
#
import sys
from test_util import parse_args, make_clients, exit_with_result
import time
def run_test(host, port):

View File

@ -3,7 +3,6 @@
# Verify forbidden command in transaction returns error without closing connection
#
import sys
from test_util import parse_args, make_client, exit_with_result

32
uv.lock generated
View File

@ -24,10 +24,14 @@ dependencies = [
{ name = "redis", version = "6.1.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.9'" },
{ name = "redis", version = "7.0.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.9.*'" },
{ name = "redis", version = "7.1.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
{ name = "ruff" },
]
[package.metadata]
requires-dist = [{ name = "redis", specifier = ">=5.0.0,<8.0.0" }]
requires-dist = [
{ name = "redis", specifier = ">=5.0.0,<8.0.0" },
{ name = "ruff", specifier = ">=0.5.0" },
]
[[package]]
name = "redis"
@ -73,3 +77,29 @@ sdist = { url = "https://files.pythonhosted.org/packages/43/c8/983d5c6579a411d8a
wheels = [
{ url = "https://files.pythonhosted.org/packages/89/f0/8956f8a86b20d7bb9d6ac0187cf4cd54d8065bc9a1a09eb8011d4d326596/redis-7.1.0-py3-none-any.whl", hash = "sha256:23c52b208f92b56103e17c5d06bdc1a6c2c0b3106583985a76a18f83b265de2b", size = 354159, upload-time = "2025-11-19T15:54:38.064Z" },
]
[[package]]
name = "ruff"
version = "0.14.11"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/d4/77/9a7fe084d268f8855d493e5031ea03fa0af8cc05887f638bf1c4e3363eb8/ruff-0.14.11.tar.gz", hash = "sha256:f6dc463bfa5c07a59b1ff2c3b9767373e541346ea105503b4c0369c520a66958", size = 5993417, upload-time = "2026-01-08T19:11:58.322Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/f0/a6/a4c40a5aaa7e331f245d2dc1ac8ece306681f52b636b40ef87c88b9f7afd/ruff-0.14.11-py3-none-linux_armv6l.whl", hash = "sha256:f6ff2d95cbd335841a7217bdfd9c1d2e44eac2c584197ab1385579d55ff8830e", size = 12951208, upload-time = "2026-01-08T19:12:09.218Z" },
{ url = "https://files.pythonhosted.org/packages/5c/5c/360a35cb7204b328b685d3129c08aca24765ff92b5a7efedbdd6c150d555/ruff-0.14.11-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:6f6eb5c1c8033680f4172ea9c8d3706c156223010b8b97b05e82c59bdc774ee6", size = 13330075, upload-time = "2026-01-08T19:12:02.549Z" },
{ url = "https://files.pythonhosted.org/packages/1b/9e/0cc2f1be7a7d33cae541824cf3f95b4ff40d03557b575912b5b70273c9ec/ruff-0.14.11-py3-none-macosx_11_0_arm64.whl", hash = "sha256:f2fc34cc896f90080fca01259f96c566f74069a04b25b6205d55379d12a6855e", size = 12257809, upload-time = "2026-01-08T19:12:00.366Z" },
{ url = "https://files.pythonhosted.org/packages/a7/e5/5faab97c15bb75228d9f74637e775d26ac703cc2b4898564c01ab3637c02/ruff-0.14.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:53386375001773ae812b43205d6064dae49ff0968774e6befe16a994fc233caa", size = 12678447, upload-time = "2026-01-08T19:12:13.899Z" },
{ url = "https://files.pythonhosted.org/packages/1b/33/e9767f60a2bef779fb5855cab0af76c488e0ce90f7bb7b8a45c8a2ba4178/ruff-0.14.11-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a697737dce1ca97a0a55b5ff0434ee7205943d4874d638fe3ae66166ff46edbe", size = 12758560, upload-time = "2026-01-08T19:11:42.55Z" },
{ url = "https://files.pythonhosted.org/packages/eb/84/4c6cf627a21462bb5102f7be2a320b084228ff26e105510cd2255ea868e5/ruff-0.14.11-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6845ca1da8ab81ab1dce755a32ad13f1db72e7fba27c486d5d90d65e04d17b8f", size = 13599296, upload-time = "2026-01-08T19:11:30.371Z" },
{ url = "https://files.pythonhosted.org/packages/88/e1/92b5ed7ea66d849f6157e695dc23d5d6d982bd6aa8d077895652c38a7cae/ruff-0.14.11-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:e36ce2fd31b54065ec6f76cb08d60159e1b32bdf08507862e32f47e6dde8bcbf", size = 15048981, upload-time = "2026-01-08T19:12:04.742Z" },
{ url = "https://files.pythonhosted.org/packages/61/df/c1bd30992615ac17c2fb64b8a7376ca22c04a70555b5d05b8f717163cf9f/ruff-0.14.11-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:590bcc0e2097ecf74e62a5c10a6b71f008ad82eb97b0a0079e85defe19fe74d9", size = 14633183, upload-time = "2026-01-08T19:11:40.069Z" },
{ url = "https://files.pythonhosted.org/packages/04/e9/fe552902f25013dd28a5428a42347d9ad20c4b534834a325a28305747d64/ruff-0.14.11-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:53fe71125fc158210d57fe4da26e622c9c294022988d08d9347ec1cf782adafe", size = 14050453, upload-time = "2026-01-08T19:11:37.555Z" },
{ url = "https://files.pythonhosted.org/packages/ae/93/f36d89fa021543187f98991609ce6e47e24f35f008dfe1af01379d248a41/ruff-0.14.11-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a35c9da08562f1598ded8470fcfef2afb5cf881996e6c0a502ceb61f4bc9c8a3", size = 13757889, upload-time = "2026-01-08T19:12:07.094Z" },
{ url = "https://files.pythonhosted.org/packages/b7/9f/c7fb6ecf554f28709a6a1f2a7f74750d400979e8cd47ed29feeaa1bd4db8/ruff-0.14.11-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:0f3727189a52179393ecf92ec7057c2210203e6af2676f08d92140d3e1ee72c1", size = 13955832, upload-time = "2026-01-08T19:11:55.064Z" },
{ url = "https://files.pythonhosted.org/packages/db/a0/153315310f250f76900a98278cf878c64dfb6d044e184491dd3289796734/ruff-0.14.11-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:eb09f849bd37147a789b85995ff734a6c4a095bed5fd1608c4f56afc3634cde2", size = 12586522, upload-time = "2026-01-08T19:11:35.356Z" },
{ url = "https://files.pythonhosted.org/packages/2f/2b/a73a2b6e6d2df1d74bf2b78098be1572191e54bec0e59e29382d13c3adc5/ruff-0.14.11-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:c61782543c1231bf71041461c1f28c64b961d457d0f238ac388e2ab173d7ecb7", size = 12724637, upload-time = "2026-01-08T19:11:47.796Z" },
{ url = "https://files.pythonhosted.org/packages/f0/41/09100590320394401cd3c48fc718a8ba71c7ddb1ffd07e0ad6576b3a3df2/ruff-0.14.11-py3-none-musllinux_1_2_i686.whl", hash = "sha256:82ff352ea68fb6766140381748e1f67f83c39860b6446966cff48a315c3e2491", size = 13145837, upload-time = "2026-01-08T19:11:32.87Z" },
{ url = "https://files.pythonhosted.org/packages/3b/d8/e035db859d1d3edf909381eb8ff3e89a672d6572e9454093538fe6f164b0/ruff-0.14.11-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:728e56879df4ca5b62a9dde2dd0eb0edda2a55160c0ea28c4025f18c03f86984", size = 13850469, upload-time = "2026-01-08T19:12:11.694Z" },
{ url = "https://files.pythonhosted.org/packages/4e/02/bb3ff8b6e6d02ce9e3740f4c17dfbbfb55f34c789c139e9cd91985f356c7/ruff-0.14.11-py3-none-win32.whl", hash = "sha256:337c5dd11f16ee52ae217757d9b82a26400be7efac883e9e852646f1557ed841", size = 12851094, upload-time = "2026-01-08T19:11:45.163Z" },
{ url = "https://files.pythonhosted.org/packages/58/f1/90ddc533918d3a2ad628bc3044cdfc094949e6d4b929220c3f0eb8a1c998/ruff-0.14.11-py3-none-win_amd64.whl", hash = "sha256:f981cea63d08456b2c070e64b79cb62f951aa1305282974d4d5216e6e0178ae6", size = 14001379, upload-time = "2026-01-08T19:11:52.591Z" },
{ url = "https://files.pythonhosted.org/packages/c4/1c/1dbe51782c0e1e9cfce1d1004752672d2d4629ea46945d19d731ad772b3b/ruff-0.14.11-py3-none-win_arm64.whl", hash = "sha256:649fb6c9edd7f751db276ef42df1f3df41c38d67d199570ae2a7bd6cbc3590f0", size = 12938644, upload-time = "2026-01-08T19:11:50.027Z" },
]