Skip to content

Commit 03bc125

Browse files
typing for client __init__ (#3357)
* typing for client __init__ * typing with string literals * retry_on_error more specific typing * retry typing * fix lint --------- Co-authored-by: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com>
1 parent e5b2d97 commit 03bc125

File tree

1 file changed

+57
-42
lines changed

1 file changed

+57
-42
lines changed

redis/client.py

+57-42
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
import time
55
import warnings
66
from itertools import chain
7-
from typing import Any, Callable, Dict, List, Optional, Type, Union
7+
from typing import (
8+
TYPE_CHECKING,
9+
Any,
10+
Callable,
11+
Dict,
12+
List,
13+
Mapping,
14+
Optional,
15+
Type,
16+
Union,
17+
)
818

919
from redis._parsers.encoders import Encoder
1020
from redis._parsers.helpers import (
@@ -53,6 +63,11 @@
5363
str_if_bytes,
5464
)
5565

66+
if TYPE_CHECKING:
67+
import ssl
68+
69+
import OpenSSL
70+
5671
SYM_EMPTY = b""
5772
EMPTY_RESPONSE = "EMPTY_RESPONSE"
5873

@@ -175,47 +190,47 @@ def from_pool(
175190

176191
def __init__(
177192
self,
178-
host="localhost",
179-
port=6379,
180-
db=0,
181-
password=None,
182-
socket_timeout=None,
183-
socket_connect_timeout=None,
184-
socket_keepalive=None,
185-
socket_keepalive_options=None,
186-
connection_pool=None,
187-
unix_socket_path=None,
188-
encoding="utf-8",
189-
encoding_errors="strict",
190-
charset=None,
191-
errors=None,
192-
decode_responses=False,
193-
retry_on_timeout=False,
194-
retry_on_error=None,
195-
ssl=False,
196-
ssl_keyfile=None,
197-
ssl_certfile=None,
198-
ssl_cert_reqs="required",
199-
ssl_ca_certs=None,
200-
ssl_ca_path=None,
201-
ssl_ca_data=None,
202-
ssl_check_hostname=False,
203-
ssl_password=None,
204-
ssl_validate_ocsp=False,
205-
ssl_validate_ocsp_stapled=False,
206-
ssl_ocsp_context=None,
207-
ssl_ocsp_expected_cert=None,
208-
ssl_min_version=None,
209-
ssl_ciphers=None,
210-
max_connections=None,
211-
single_connection_client=False,
212-
health_check_interval=0,
213-
client_name=None,
214-
lib_name="redis-py",
215-
lib_version=get_lib_version(),
216-
username=None,
217-
retry=None,
218-
redis_connect_func=None,
193+
host: str = "localhost",
194+
port: int = 6379,
195+
db: int = 0,
196+
password: Optional[str] = None,
197+
socket_timeout: Optional[float] = None,
198+
socket_connect_timeout: Optional[float] = None,
199+
socket_keepalive: Optional[bool] = None,
200+
socket_keepalive_options: Optional[Mapping[int, Union[int, bytes]]] = None,
201+
connection_pool: Optional[ConnectionPool] = None,
202+
unix_socket_path: Optional[str] = None,
203+
encoding: str = "utf-8",
204+
encoding_errors: str = "strict",
205+
charset: Optional[str] = None,
206+
errors: Optional[str] = None,
207+
decode_responses: bool = False,
208+
retry_on_timeout: bool = False,
209+
retry_on_error: Optional[List[Type[Exception]]] = None,
210+
ssl: bool = False,
211+
ssl_keyfile: Optional[str] = None,
212+
ssl_certfile: Optional[str] = None,
213+
ssl_cert_reqs: str = "required",
214+
ssl_ca_certs: Optional[str] = None,
215+
ssl_ca_path: Optional[str] = None,
216+
ssl_ca_data: Optional[str] = None,
217+
ssl_check_hostname: bool = False,
218+
ssl_password: Optional[str] = None,
219+
ssl_validate_ocsp: bool = False,
220+
ssl_validate_ocsp_stapled: bool = False,
221+
ssl_ocsp_context: Optional["OpenSSL.SSL.Context"] = None,
222+
ssl_ocsp_expected_cert: Optional[str] = None,
223+
ssl_min_version: Optional["ssl.TLSVersion"] = None,
224+
ssl_ciphers: Optional[str] = None,
225+
max_connections: Optional[int] = None,
226+
single_connection_client: bool = False,
227+
health_check_interval: int = 0,
228+
client_name: Optional[str] = None,
229+
lib_name: Optional[str] = "redis-py",
230+
lib_version: Optional[str] = get_lib_version(),
231+
username: Optional[str] = None,
232+
retry: Optional[Retry] = None,
233+
redis_connect_func: Optional[Callable[[], None]] = None,
219234
credential_provider: Optional[CredentialProvider] = None,
220235
protocol: Optional[int] = 2,
221236
cache: Optional[CacheInterface] = None,

0 commit comments

Comments
 (0)