11from copy import deepcopy
22from sys import version_info
3- from typing import Any , Dict , List , Optional , Tuple , Union
3+ from typing import Any , Dict , Optional , Union
44from urllib .parse import quote
55
66from algoliasearch .http .base_config import BaseConfig
1313
1414
1515class 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-
2216 def __init__ (
2317 self ,
2418 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 ,
2923 ) -> None :
24+ if headers is None :
25+ headers = {}
26+ if query_parameters is None :
27+ query_parameters = {}
28+ if timeouts is None :
29+ timeouts = {}
3030 self ._config = config
3131 self .headers = headers
3232 self .query_parameters = {
@@ -51,25 +51,28 @@ def from_dict(self, data: Dict[str, Dict[str, Any]]) -> Self:
5151 query_parameters = data .get ("query_parameters" , {}),
5252 timeouts = data .get ("timeouts" , {}),
5353 data = data .get ("data" , {}),
54- )
54+ ) # pyright: ignore
5555
5656 def merge (
5757 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 ,
6160 data : Optional [str ] = None ,
6261 user_request_options : Optional [Union [Self , Dict [str , Any ]]] = None ,
6362 ) -> Self :
6463 """
6564 Merges the default config values with the user given request options if it exists.
6665 """
6766
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 {})
6972
7073 request_options = {
7174 "headers" : headers ,
72- "query_parameters" : { k : v for k , v in query_parameters } ,
75+ "query_parameters" : query_parameters ,
7376 "timeouts" : {
7477 "read" : self ._config .read_timeout ,
7578 "write" : self ._config .write_timeout ,
0 commit comments