diff --git a/.flake8 b/.flake8 index 73b4a96bb6..d2ee181447 100644 --- a/.flake8 +++ b/.flake8 @@ -16,6 +16,8 @@ exclude = ignore = E126 E203 + E701 + E704 F405 N801 N802 diff --git a/dev_requirements.txt b/dev_requirements.txt index 3715599af0..ef3b1aa22d 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,5 +1,5 @@ click==8.0.4 -black==22.3.0 +black==24.3.0 flake8==5.0.4 flake8-isort==6.0.0 flynt~=0.69.0 diff --git a/redis/_parsers/helpers.py b/redis/_parsers/helpers.py index bdd749a5bc..a1df927bf3 100644 --- a/redis/_parsers/helpers.py +++ b/redis/_parsers/helpers.py @@ -819,18 +819,19 @@ def string_keys_to_dict(key_string, callback): lambda r, **kwargs: r, ), **string_keys_to_dict("XREAD XREADGROUP", parse_xread_resp3), - "ACL LOG": lambda r: [ - {str_if_bytes(key): str_if_bytes(value) for key, value in x.items()} for x in r - ] - if isinstance(r, list) - else bool_ok(r), + "ACL LOG": lambda r: ( + [ + {str_if_bytes(key): str_if_bytes(value) for key, value in x.items()} + for x in r + ] + if isinstance(r, list) + 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) - if value is not None - else None + 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() }, "MEMORY STATS": lambda r: {str_if_bytes(key): value for key, value in r.items()}, @@ -838,11 +839,11 @@ def string_keys_to_dict(key_string, callback): "SENTINEL MASTERS": parse_sentinel_masters_resp3, "SENTINEL SENTINELS": parse_sentinel_slaves_and_sentinels_resp3, "SENTINEL SLAVES": parse_sentinel_slaves_and_sentinels_resp3, - "STRALGO": lambda r, **options: { - str_if_bytes(key): str_if_bytes(value) for key, value in r.items() - } - if isinstance(r, dict) - else str_if_bytes(r), + "STRALGO": lambda r, **options: ( + {str_if_bytes(key): str_if_bytes(value) for key, value in r.items()} + if isinstance(r, dict) + else str_if_bytes(r) + ), "XINFO CONSUMERS": lambda r: [ {str_if_bytes(key): value for key, value in x.items()} for x in r ], diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 9ff2e3917f..e153f0cd37 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -88,13 +88,11 @@ class ResponseCallbackProtocol(Protocol): - def __call__(self, response: Any, **kwargs): - ... + def __call__(self, response: Any, **kwargs): ... class AsyncResponseCallbackProtocol(Protocol): - async def __call__(self, response: Any, **kwargs): - ... + async def __call__(self, response: Any, **kwargs): ... ResponseCallbackT = Union[ResponseCallbackProtocol, AsyncResponseCallbackProtocol] @@ -1220,13 +1218,11 @@ async def run( class PubsubWorkerExceptionHandler(Protocol): - def __call__(self, e: BaseException, pubsub: PubSub): - ... + def __call__(self, e: BaseException, pubsub: PubSub): ... class AsyncPubsubWorkerExceptionHandler(Protocol): - async def __call__(self, e: BaseException, pubsub: PubSub): - ... + async def __call__(self, e: BaseException, pubsub: PubSub): ... PSWorkerThreadExcHandlerT = Union[ diff --git a/redis/asyncio/cluster.py b/redis/asyncio/cluster.py index 11c423b848..ff2bd10c9d 100644 --- a/redis/asyncio/cluster.py +++ b/redis/asyncio/cluster.py @@ -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 @@ -1318,9 +1318,9 @@ async def initialize(self) -> None: ) tmp_slots[i].append(target_replica_node) # add this node to the nodes cache - tmp_nodes_cache[ - target_replica_node.name - ] = target_replica_node + tmp_nodes_cache[target_replica_node.name] = ( + target_replica_node + ) else: # Validate that 2 nodes want to use the same slot cache # setup diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 6c5c58c683..2e470bfcfb 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -87,13 +87,11 @@ class _Sentinel(enum.Enum): class ConnectCallbackProtocol(Protocol): - def __call__(self, connection: "AbstractConnection"): - ... + def __call__(self, connection: "AbstractConnection"): ... class AsyncConnectCallbackProtocol(Protocol): - async def __call__(self, connection: "AbstractConnection"): - ... + async def __call__(self, connection: "AbstractConnection"): ... ConnectCallbackT = Union[ConnectCallbackProtocol, AsyncConnectCallbackProtocol] @@ -319,9 +317,11 @@ async def connect(self): await self.on_connect() else: # Use the passed function redis_connect_func - await self.redis_connect_func(self) if asyncio.iscoroutinefunction( - self.redis_connect_func - ) else self.redis_connect_func(self) + ( + await self.redis_connect_func(self) + if asyncio.iscoroutinefunction(self.redis_connect_func) + else self.redis_connect_func(self) + ) except RedisError: # clean up after any error in on_connect await self.disconnect() diff --git a/redis/asyncio/sentinel.py b/redis/asyncio/sentinel.py index d88babc59c..6fd233adc8 100644 --- a/redis/asyncio/sentinel.py +++ b/redis/asyncio/sentinel.py @@ -108,9 +108,11 @@ class SentinelConnectionPool(ConnectionPool): def __init__(self, service_name, sentinel_manager, **kwargs): kwargs["connection_class"] = kwargs.get( "connection_class", - SentinelManagedSSLConnection - if kwargs.pop("ssl", False) - else SentinelManagedConnection, + ( + SentinelManagedSSLConnection + if kwargs.pop("ssl", False) + else SentinelManagedConnection + ), ) self.is_master = kwargs.pop("is_master", True) self.check_connection = kwargs.pop("check_connection", False) diff --git a/redis/cluster.py b/redis/cluster.py index a9213f4235..cfe902115e 100644 --- a/redis/cluster.py +++ b/redis/cluster.py @@ -1582,9 +1582,9 @@ def initialize(self): ) tmp_slots[i].append(target_replica_node) # add this node to the nodes cache - tmp_nodes_cache[ - target_replica_node.name - ] = target_replica_node + tmp_nodes_cache[target_replica_node.name] = ( + target_replica_node + ) else: # Validate that 2 nodes want to use the same slot cache # setup diff --git a/redis/commands/core.py b/redis/commands/core.py index 464e8d8c85..566846a20e 100644 --- a/redis/commands/core.py +++ b/redis/commands/core.py @@ -3399,9 +3399,7 @@ 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/exceptions.py b/redis/exceptions.py index 8af58cb0db..dcc06774b0 100644 --- a/redis/exceptions.py +++ b/redis/exceptions.py @@ -217,5 +217,4 @@ class SlotNotCoveredError(RedisClusterException): pass -class MaxConnectionsError(ConnectionError): - ... +class MaxConnectionsError(ConnectionError): ... diff --git a/redis/sentinel.py b/redis/sentinel.py index dfcd8ff64b..72b5bef548 100644 --- a/redis/sentinel.py +++ b/redis/sentinel.py @@ -145,9 +145,11 @@ class SentinelConnectionPool(ConnectionPool): def __init__(self, service_name, sentinel_manager, **kwargs): kwargs["connection_class"] = kwargs.get( "connection_class", - SentinelManagedSSLConnection - if kwargs.pop("ssl", False) - else SentinelManagedConnection, + ( + SentinelManagedSSLConnection + if kwargs.pop("ssl", False) + else SentinelManagedConnection + ), ) self.is_master = kwargs.pop("is_master", True) self.check_connection = kwargs.pop("check_connection", False) diff --git a/redis/typing.py b/redis/typing.py index a5d1369d63..838219fbb6 100644 --- a/redis/typing.py +++ b/redis/typing.py @@ -54,12 +54,10 @@ class CommandsProtocol(Protocol): connection_pool: Union["AsyncConnectionPool", "ConnectionPool"] - def execute_command(self, *args, **options): - ... + def execute_command(self, *args, **options): ... class ClusterCommandsProtocol(CommandsProtocol, Protocol): encoder: "Encoder" - def execute_command(self, *args, **options) -> Union[Any, Awaitable]: - ... + def execute_command(self, *args, **options) -> Union[Any, Awaitable]: ... diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index 35b9f2a29f..7102450fe4 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -1,6 +1,7 @@ """ Tests async overrides of commands from their mixins """ + import asyncio import binascii import datetime