Skip to content

Commit 8188e5f

Browse files
author
Mikhail Koviazin
committed
update types in connection.py to match Python 3.9
Signed-off-by: Mikhail Koviazin <mikhail.koviazin@aiven.io>
1 parent 882cbeb commit 8188e5f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

valkey/connection.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import threading
66
import weakref
77
from abc import abstractmethod
8+
from collections.abc import Callable, Iterable, Sequence
89
from itertools import chain
910

1011
# We need to explicitly import `getpid` from `os` instead of importing `os`. The
@@ -23,7 +24,7 @@
2324
from os import getpid
2425
from queue import Empty, Full, LifoQueue
2526
from time import time
26-
from typing import Any, Callable, Iterable, List, Optional, Sequence, Tuple, Type, Union
27+
from typing import Any, Optional, Union
2728

2829
from ._cache import (
2930
DEFAULT_ALLOW_LIST,
@@ -66,17 +67,17 @@
6667

6768
DEFAULT_RESP_VERSION = 2
6869

69-
DefaultParser: Type[Union[_RESP2Parser, _RESP3Parser, _LibvalkeyParser]]
70+
DefaultParser: type[Union[_RESP2Parser, _RESP3Parser, _LibvalkeyParser]]
7071
if LIBVALKEY_AVAILABLE:
7172
DefaultParser = _LibvalkeyParser
7273
else:
7374
DefaultParser = _RESP2Parser
7475

7576

7677
class LibvalkeyRespSerializer:
77-
def pack(self, *args) -> List[bytes]:
78+
def pack(self, *args) -> list[bytes]:
7879
"""Pack a series of arguments into the Valkey protocol"""
79-
output: List[bytes] = []
80+
output: list[bytes] = []
8081

8182
if isinstance(args[0], str):
8283
args = tuple(args[0].encode().split()) + args[1:]
@@ -96,7 +97,7 @@ def __init__(self, buffer_cutoff, encode) -> None:
9697
self._buffer_cutoff = buffer_cutoff
9798
self.encode = encode
9899

99-
def pack(self, *args) -> List[bytes]:
100+
def pack(self, *args) -> list[bytes]:
100101
"""Pack a series of arguments into the Valkey protocol"""
101102
output = []
102103
# the client might have included 1 or more literal arguments in
@@ -152,7 +153,7 @@ def __init__(
152153
socket_timeout: Optional[float] = 5,
153154
socket_connect_timeout: Optional[float] = None,
154155
retry_on_timeout: bool = False,
155-
retry_on_error: Optional[List[Type[Exception]]] = None,
156+
retry_on_error: Optional[list[type[Exception]]] = None,
156157
encoding: str = "utf-8",
157158
encoding_errors: str = "strict",
158159
decode_responses: bool = False,
@@ -173,8 +174,8 @@ def __init__(
173174
cache_max_size: int = 10000,
174175
cache_ttl: int = 0,
175176
cache_policy=DEFAULT_EVICTION_POLICY,
176-
cache_deny_list: List[str] = DEFAULT_DENY_LIST,
177-
cache_allow_list: List[str] = DEFAULT_ALLOW_LIST,
177+
cache_deny_list: list[str] = DEFAULT_DENY_LIST,
178+
cache_allow_list: list[str] = DEFAULT_ALLOW_LIST,
178179
):
179180
"""
180181
Initialize a new Connection.
@@ -226,7 +227,7 @@ def __init__(
226227
self._sock: Optional[socket.socket] = None
227228
self._socket_read_size = socket_read_size
228229
self.set_parser(parser_class)
229-
self._connect_callbacks: List[weakref.WeakMethod] = []
230+
self._connect_callbacks: list[weakref.WeakMethod] = []
230231
self._buffer_cutoff = 6000
231232
try:
232233
p = int(protocol) if protocol is not None else DEFAULT_RESP_VERSION
@@ -256,7 +257,7 @@ def __repr__(self):
256257
return f"<{self.__class__.__module__}.{self.__class__.__name__}({repr_args})>"
257258

258259
@abstractmethod
259-
def repr_pieces(self) -> List[Tuple[str, Any]]:
260+
def repr_pieces(self) -> list[tuple[str, Any]]:
260261
pass
261262

262263
def __del__(self):
@@ -589,8 +590,8 @@ def pack_command(self, *args):
589590

590591
def pack_commands(self, commands):
591592
"""Pack multiple commands into the Valkey protocol"""
592-
output: List[bytes] = []
593-
pieces: List[bytes] = []
593+
output: list[bytes] = []
594+
pieces: list[bytes] = []
594595
buffer_length = 0
595596
buffer_cutoff = self._buffer_cutoff
596597

@@ -618,7 +619,7 @@ def pack_commands(self, commands):
618619
return output
619620

620621
def _cache_invalidation_process(
621-
self, data: List[Union[str, Optional[List[str]]]]
622+
self, data: list[Union[str, Optional[list[str]]]]
622623
) -> None:
623624
"""
624625
Invalidate (delete) all valkey commands associated with a specific key.
@@ -648,7 +649,7 @@ def _get_from_local_cache(self, command: Sequence[str]):
648649
return self.client_cache.get(command)
649650

650651
def _add_to_local_cache(
651-
self, command: Sequence[str], response: ResponseT, keys: List[KeyT]
652+
self, command: Sequence[str], response: ResponseT, keys: list[KeyT]
652653
):
653654
"""
654655
Add the command and response to the local cache if the command

0 commit comments

Comments
 (0)