Skip to content
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

Replace flake8+isort+black with ruff #3147

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 0 additions & 25 deletions .flake8

This file was deleted.

5 changes: 0 additions & 5 deletions .isort.cfg

This file was deleted.

1 change: 0 additions & 1 deletion benchmarks/command_packer_benchmark.py
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
Expand Up @@ -4,7 +4,6 @@


class SocketReadBenchmark(Benchmark):

ARGUMENTS = (
{"name": "parser", "values": [PythonParser, _HiredisParser]},
{
Expand Down
4 changes: 1 addition & 3 deletions dev_requirements.txt
@@ -1,7 +1,5 @@
click==8.0.4
black==22.3.0
flake8==5.0.4
flake8-isort==6.0.0
ruff==0.2.1
flynt~=0.69.0
mock==4.0.3
packaging>=20.4
Expand Down
6 changes: 2 additions & 4 deletions redis/_parsers/helpers.py
Expand Up @@ -490,7 +490,7 @@ def parse_geosearch_generic(response, **options):
except KeyError: # it means the command was sent via execute_command
return response

if type(response) != list:
if type(response) != list: # noqa: E721
response_list = [response]
else:
response_list = response
Expand Down Expand Up @@ -826,9 +826,7 @@ def string_keys_to_dict(key_string, callback):
else bool_ok(r),
"COMMAND": parse_command_resp3,
"CONFIG GET": lambda r: {
str_if_bytes(key)
if key is not None
else None: str_if_bytes(value)
str_if_bytes(key) if key is not None else None: str_if_bytes(value)
if value is not None
else None
for key, value in r.items()
Expand Down
8 changes: 4 additions & 4 deletions redis/asyncio/cluster.py
Expand Up @@ -402,10 +402,10 @@ def __init__(
self.command_flags = self.__class__.COMMAND_FLAGS.copy()
self.response_callbacks = kwargs["response_callbacks"]
self.result_callbacks = self.__class__.RESULT_CALLBACKS.copy()
self.result_callbacks[
"CLUSTER SLOTS"
] = lambda cmd, res, **kwargs: parse_cluster_slots(
list(res.values())[0], **kwargs
self.result_callbacks["CLUSTER SLOTS"] = (
lambda cmd, res, **kwargs: parse_cluster_slots(
list(res.values())[0], **kwargs
)
)

self._initialize = True
Expand Down
2 changes: 1 addition & 1 deletion redis/commands/graph/__init__.py
Expand Up @@ -252,7 +252,7 @@ async def call_procedure(self, procedure, *args, read_only=False, **kwagrs):
return await self.query(q, read_only=read_only)

async def labels(self):
return ((await self.call_procedure(DB_LABELS, read_only=True))).result_set
return (await self.call_procedure(DB_LABELS, read_only=True)).result_set

async def property_keys(self):
return (await self.call_procedure(DB_PROPERTYKEYS, read_only=True)).result_set
Expand Down
4 changes: 1 addition & 3 deletions redis/commands/graph/commands.py
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
2 changes: 1 addition & 1 deletion redis/commands/timeseries/info.py
Expand Up @@ -78,7 +78,7 @@ def __init__(self, args):
self.chunk_size = response["chunkSize"]
if "duplicatePolicy" in response:
self.duplicate_policy = response["duplicatePolicy"]
if type(self.duplicate_policy) == bytes:
if type(self.duplicate_policy) == bytes: # noqa: E721
self.duplicate_policy = self.duplicate_policy.decode()

def get(self, item):
Expand Down
3 changes: 3 additions & 0 deletions redis/exceptions.py
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, 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
1 change: 1 addition & 0 deletions redis/ocsp.py
Expand Up @@ -15,6 +15,7 @@
from cryptography.hazmat.primitives.hashes import SHA1, Hash
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from cryptography.x509 import ocsp

from redis.exceptions import AuthorizationError, ConnectionError


Expand Down
37 changes: 37 additions & 0 deletions ruff.toml
@@ -0,0 +1,37 @@
line-length = 88
exclude = [
"*.egg-info",
"*.pyc",
".git",
".venv*",
".venv*",
"build",
"dist",
"docker",
"docs/*",
"tasks.py",
"venv*",
"whitelist.py",
]
[lint]
ignore = [
"E501",
"E741",
"F405",
"N801",
"N802",
"N803",
"N806",
"N815",
"N818",
]
extend-select = [
"E",
"F",
"N",
"W",
"I",
]
[lint.per-file-ignores]
"redis/commands/search/indexDefinition.py" = ["N999"]
"tests/*" = ["I"]
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -37,7 +37,7 @@
python_requires=">=3.8",
install_requires=[
'typing-extensions; python_version<"3.8"',
'async-timeout>=4.0.3',
"async-timeout>=4.0.3",
],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
4 changes: 2 additions & 2 deletions tasks.py
Expand Up @@ -27,8 +27,8 @@ def build_docs(c):
@task
def linters(c):
"""Run code linters"""
run("flake8 tests redis")
run("black --target-version py37 --check --diff tests redis")
run("ruff tests redis")
run("ruff format --check --diff tests redis")
run("isort --check-only --diff tests redis")
run("vulture redis whitelist.py --min-confidence 80")
run("flynt --fail-on-change --dry-run tests redis")
Expand Down
5 changes: 3 additions & 2 deletions tests/test_commands.py
Expand Up @@ -3173,8 +3173,9 @@ 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)
r"^{0}\.hmset\(\) is deprecated\. " r"Use {0}\.hset\(\) instead\.$".format(
redis_class
)
)
h = {b"a": b"1", b"b": b"2", b"c": b"3"}
with pytest.warns(DeprecationWarning, match=warning_message):
Expand Down