Skip to content

Commit bd942ee

Browse files
committed
Fixed linter errors and asyncio use in test_cluster()
1 parent c97bffa commit bd942ee

19 files changed

+119
-108
lines changed

redis/anyio/_commands/cluster.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
Optional,
1111
)
1212

13-
from ..utils import gather
1413
from ...commands.cluster import (
15-
ClusterDataAccessCommands, ClusterManagementCommands,
16-
ClusterMultiKeyCommands, READ_COMMANDS,
14+
READ_COMMANDS,
15+
ClusterDataAccessCommands,
16+
ClusterManagementCommands,
17+
ClusterMultiKeyCommands,
1718
)
1819
from ...commands.core import (
1920
AsyncACLCommands,
@@ -25,7 +26,8 @@
2526
)
2627
from ...commands.helpers import list_or_args
2728
from ...commands.redismodules import AsyncRedisModuleCommands
28-
from ...typing import AnyKeyT, EncodableT, KeyT, KeysT, PatternT
29+
from ...typing import AnyKeyT, EncodableT, KeysT, KeyT, PatternT
30+
from ..utils import gather
2931

3032

3133
class AsyncClusterMultiKeyCommands(ClusterMultiKeyCommands):
@@ -125,10 +127,7 @@ async def cluster_delslots(self, *slots: EncodableT) -> Sequence[bool]:
125127
For more information see https://redis.io/commands/cluster-delslots
126128
"""
127129
return await gather(
128-
*(
129-
self.execute_command("CLUSTER DELSLOTS", slot)
130-
for slot in slots
131-
)
130+
*(self.execute_command("CLUSTER DELSLOTS", slot) for slot in slots)
132131
)
133132

134133

redis/anyio/_parsers/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from anyio.abc import ByteStream
88
from anyio.streams.buffered import BufferedByteReceiveStream
99

10-
from redis.exceptions import RedisError, ResponseError
1110
from redis._parsers import BaseParser, Encoder
11+
from redis.exceptions import RedisError, ResponseError
1212
from redis.typing import EncodableT
13+
1314
from ..._parsers.socket import SERVER_CLOSED_CONNECTION_ERROR
1415

1516

redis/anyio/_parsers/hiredis.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
from anyio import BrokenResourceError, EndOfStream, move_on_after
77

8+
from ..._parsers.socket import (
9+
SERVER_CLOSED_CONNECTION_ERROR,
10+
)
811
from ...exceptions import ConnectionError, InvalidResponse, RedisError
912
from ...typing import EncodableT
1013
from ...utils import HIREDIS_AVAILABLE
1114
from .base import AnyIOBaseParser
12-
from ..._parsers.socket import (
13-
SENTINEL,
14-
SERVER_CLOSED_CONNECTION_ERROR,
15-
)
1615

1716
# Used to signal that hiredis-py does not have enough data to parse.
1817
# Using `False` or `None` is not reliable, given that the parser can

redis/anyio/_parsers/resp2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from typing import Any
44

5+
from ..._parsers.socket import SERVER_CLOSED_CONNECTION_ERROR
56
from ...exceptions import ConnectionError, InvalidResponse, ResponseError
67
from ...typing import EncodableT
78
from .base import _AnyIORESPBase
8-
from ..._parsers.socket import SERVER_CLOSED_CONNECTION_ERROR
99

1010

1111
class _AnyIORESP2Parser(_AnyIORESPBase):

redis/anyio/_parsers/resp3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from logging import getLogger
44
from typing import Any
55

6+
from ..._parsers.socket import SERVER_CLOSED_CONNECTION_ERROR
67
from ...exceptions import ConnectionError, InvalidResponse, ResponseError
78
from ...typing import EncodableT
89
from .base import _AnyIORESPBase
9-
from ..._parsers.socket import SERVER_CLOSED_CONNECTION_ERROR
1010

1111
_INVALIDATION_MESSAGE = [b"invalidate", "invalidate"]
1212

redis/anyio/client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,7 @@ async def check_health(self):
987987
"did you forget to call subscribe() or psubscribe()?"
988988
)
989989

990-
if (
991-
conn.health_check_interval
992-
and anyio.current_time() > conn.next_health_check
993-
):
990+
if conn.health_check_interval and anyio.current_time() > conn.next_health_check:
994991
await conn.send_command(
995992
"PING", self.HEALTH_CHECK_MESSAGE, check_health=False
996993
)

redis/anyio/cluster.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Callable,
1313
Deque,
1414
Dict,
15-
Generator,
1615
List,
1716
Mapping,
1817
Optional,
@@ -461,7 +460,7 @@ async def __aexit__(
461460
self,
462461
exc_type: type[BaseException] | None,
463462
exc_value: BaseException | None,
464-
exc_tb: TracebackType | None
463+
exc_tb: TracebackType | None,
465464
) -> None:
466465
exit_stack, self._exit_stack = self._exit_stack, None
467466
await exit_stack.__aexit__(exc_type, exc_value, exc_tb)
@@ -471,7 +470,9 @@ def __del__(
471470
_warn: Any = warnings.warn,
472471
) -> None:
473472
if getattr(self, "_exit_stack", None) is not None:
474-
_warn(f"Unclosed RedisCluster client {self!r}", ResourceWarning, source=self)
473+
_warn(
474+
f"Unclosed RedisCluster client {self!r}", ResourceWarning, source=self
475+
)
475476

476477
async def on_connect(self, connection: Connection) -> None:
477478
await connection.on_connect()
@@ -1428,7 +1429,7 @@ async def __aexit__(
14281429
self,
14291430
exc_type: type[BaseException] | None,
14301431
exc_value: BaseException | None,
1431-
exc_tb: TracebackType | None
1432+
exc_tb: TracebackType | None,
14321433
) -> bool | None:
14331434
try:
14341435
return await self._exit_stack.__aexit__(exc_type, exc_value, exc_tb)
@@ -1446,12 +1447,7 @@ async def __aexit__(
14461447

14471448
async def aclose(self, attr: str = "nodes_cache") -> None:
14481449
self.default_node = None
1449-
await gather(
1450-
*(
1451-
node.disconnect()
1452-
for node in getattr(self, attr).values()
1453-
)
1454-
)
1450+
await gather(*(node.disconnect() for node in getattr(self, attr).values()))
14551451

14561452
def remap_host_port(self, host: str, port: int) -> Tuple[str, int]:
14571453
"""
@@ -1632,10 +1628,7 @@ async def _execute(
16321628
nodes[node.name][1].append(cmd)
16331629

16341630
errors = await gather(
1635-
*(
1636-
node[0].execute_pipeline(node[1])
1637-
for node in nodes.values()
1638-
)
1631+
*(node[0].execute_pipeline(node[1]) for node in nodes.values())
16391632
)
16401633

16411634
if any(errors):

redis/anyio/connection.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
from anyio import BrokenResourceError, aclose_forcefully
3232
from anyio.abc import SocketAttribute, SocketStream
3333

34+
from ..utils import SSL_AVAILABLE
3435
from ._parsers.base import AnyIOBaseParser
3536
from .utils import wait_for_condition
36-
from ..utils import SSL_AVAILABLE
3737

3838
if SSL_AVAILABLE:
3939
import ssl
@@ -43,10 +43,6 @@
4343
TLSVersion = None
4444
SSLContext = None
4545

46-
from ..auth.token import TokenInterface
47-
from ..event import AsyncAfterConnectionReleasedEvent, EventDispatcher
48-
from ..utils import deprecated_args, format_error_message
49-
5046
from redis.anyio.retry import Retry
5147
from redis.backoff import NoBackoff
5248
from redis.connection import DEFAULT_RESP_VERSION
@@ -64,9 +60,11 @@
6460
from redis.utils import HIREDIS_AVAILABLE, get_lib_version, str_if_bytes
6561

6662
from .._parsers import (
67-
BaseParser,
6863
Encoder,
6964
)
65+
from ..auth.token import TokenInterface
66+
from ..event import AsyncAfterConnectionReleasedEvent, EventDispatcher
67+
from ..utils import deprecated_args, format_error_message
7068
from ._parsers import (
7169
_AnyIOHiredisParser,
7270
_AnyIORESP2Parser,
@@ -234,9 +232,7 @@ def __del__(
234232
# collected and therefore produce no resource warnings. We add one
235233
# here, in the same style as those from the stdlib.
236234
if getattr(self, "_stream", None):
237-
_warn(
238-
f"unclosed Connection {self!r}", ResourceWarning, source=self
239-
)
235+
_warn(f"unclosed Connection {self!r}", ResourceWarning, source=self)
240236

241237
def __repr__(self):
242238
repr_args = ",".join((f"{k}={v}" for k, v in self.repr_pieces()))
@@ -488,10 +484,7 @@ async def _ping_failed(self, error):
488484

489485
async def check_health(self):
490486
"""Check the health of the connection with a PING/PONG"""
491-
if (
492-
self.health_check_interval
493-
and anyio.current_time() > self.next_health_check
494-
):
487+
if self.health_check_interval and anyio.current_time() > self.next_health_check:
495488
await self.retry.call_with_retry(self._send_ping, self._ping_failed)
496489

497490
async def _send_packed_command(self, command: Iterable[bytes]) -> None:

redis/anyio/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from collections.abc import Callable, Coroutine, Sequence
4-
from typing import Any, TYPE_CHECKING
4+
from typing import TYPE_CHECKING, Any
55

66
import anyio
77

redis/commands/core.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
from .helpers import list_or_args
5454

5555
if TYPE_CHECKING:
56-
import redis.asyncio.client
5756
import redis.anyio.client
57+
import redis.asyncio.client
5858
import redis.client
5959

6060

@@ -1453,7 +1453,7 @@ def __init__(
14531453
client: Union[
14541454
"redis.client.Redis",
14551455
"redis.asyncio.client.Redis",
1456-
"redis.anyio.client.Redis"
1456+
"redis.anyio.client.Redis",
14571457
],
14581458
key: str,
14591459
default_overflow: Union[str, None] = None,
@@ -1601,7 +1601,7 @@ def bitfield(
16011601
self: Union[
16021602
"redis.client.Redis",
16031603
"redis.asyncio.client.Redis",
1604-
"redis.anyio.client.Redis"
1604+
"redis.anyio.client.Redis",
16051605
],
16061606
key: KeyT,
16071607
default_overflow: Union[str, None] = None,
@@ -1618,7 +1618,7 @@ def bitfield_ro(
16181618
self: Union[
16191619
"redis.client.Redis",
16201620
"redis.asyncio.client.Redis",
1621-
"redis.anyio.client.Redis"
1621+
"redis.anyio.client.Redis",
16221622
],
16231623
key: KeyT,
16241624
encoding: str,
@@ -5706,7 +5706,9 @@ async def __call__(
57065706
self,
57075707
keys: Union[Sequence[KeyT], None] = None,
57085708
args: Union[Iterable[EncodableT], None] = None,
5709-
client: Union["redis.asyncio.client.Redis", "redis.anyio.client.Redis", None] = None,
5709+
client: Union[
5710+
"redis.asyncio.client.Redis", "redis.anyio.client.Redis", None
5711+
] = None,
57105712
):
57115713
"""Execute the script, passing any required ``args``"""
57125714
keys = keys or []
@@ -5715,8 +5717,8 @@ async def __call__(
57155717
client = self.registered_client
57165718
args = tuple(keys) + tuple(args)
57175719
# make sure the Redis server knows about the script
5718-
from redis.asyncio.client import Pipeline as AsyncioPipeline
57195720
from redis.anyio.client import Pipeline as AnyioPipeline
5721+
from redis.asyncio.client import Pipeline as AsyncioPipeline
57205722

57215723
if isinstance(client, (AsyncioPipeline, AnyioPipeline)):
57225724
# Make sure the pipeline can register the script before executing.

0 commit comments

Comments
 (0)