1
1
from copy import deepcopy
2
2
from sys import version_info
3
- from typing import Any , Dict , List , Optional , Tuple , Union
3
+ from typing import Any , Dict , Optional , Union
4
4
from urllib .parse import quote
5
5
6
6
from algoliasearch .http .base_config import BaseConfig
13
13
14
14
15
15
class RequestOptions :
16
- _config : BaseConfig
17
- headers : Dict [str , str ]
18
- query_parameters : Dict [str , Any ]
19
- timeouts : Dict [str , int ]
20
- data : Dict [str , Any ]
21
-
22
16
def __init__ (
23
17
self ,
24
18
config : BaseConfig ,
25
- headers : Dict [str , str ] = {} ,
26
- query_parameters : Dict [str , Any ] = {} ,
27
- timeouts : Dict [str , int ] = {} ,
28
- data : Dict [str , Any ] = {} ,
19
+ headers : Optional [ Dict [str , str ]] = None ,
20
+ query_parameters : Optional [ Dict [str , Any ]] = None ,
21
+ timeouts : Optional [ Dict [str , int ]] = None ,
22
+ data : Optional [ Dict [str , Any ]] = None ,
29
23
) -> None :
24
+ if headers is None :
25
+ headers = {}
26
+ if query_parameters is None :
27
+ query_parameters = {}
28
+ if timeouts is None :
29
+ timeouts = {}
30
30
self ._config = config
31
31
self .headers = headers
32
32
self .query_parameters = {
@@ -51,25 +51,28 @@ def from_dict(self, data: Dict[str, Dict[str, Any]]) -> Self:
51
51
query_parameters = data .get ("query_parameters" , {}),
52
52
timeouts = data .get ("timeouts" , {}),
53
53
data = data .get ("data" , {}),
54
- )
54
+ ) # pyright: ignore
55
55
56
56
def merge (
57
57
self ,
58
- query_parameters : List [Tuple [str , str ]] = [],
59
- headers : Dict [str , Optional [str ]] = {},
60
- _ : Dict [str , int ] = {},
58
+ query_parameters : Optional [Dict [str , Any ]] = None ,
59
+ headers : Optional [Dict [str , str ]] = None ,
61
60
data : Optional [str ] = None ,
62
61
user_request_options : Optional [Union [Self , Dict [str , Any ]]] = None ,
63
62
) -> Self :
64
63
"""
65
64
Merges the default config values with the user given request options if it exists.
66
65
"""
67
66
68
- headers .update (self ._config .headers )
67
+ if query_parameters is None :
68
+ query_parameters = {}
69
+ if headers is None :
70
+ headers = {}
71
+ headers .update (self ._config .headers or {})
69
72
70
73
request_options = {
71
74
"headers" : headers ,
72
- "query_parameters" : { k : v for k , v in query_parameters } ,
75
+ "query_parameters" : query_parameters ,
73
76
"timeouts" : {
74
77
"read" : self ._config .read_timeout ,
75
78
"write" : self ._config .write_timeout ,
0 commit comments