3333class _BaseHttpClient :
3434 """Base class for HTTP clients with shared configuration and utilities."""
3535
36- def __init__ (self , config : ClientConfig , stats : ClientStatistics | None = None ) -> None :
36+ def __init__ (self , config : ClientConfig , statistics : ClientStatistics | None = None ) -> None :
3737 """Initialize HTTP client with configuration.
3838
3939 Args:
4040 config: Immutable client configuration.
41- stats : Optional statistics tracker.
41+ statistics : Optional statistics tracker.
4242 """
43- self .config = config
44- self .stats = stats or ClientStatistics ()
43+ self ._config = config
44+ self ._statistics = statistics or ClientStatistics ()
4545
4646 # Build headers
4747 headers = {'Accept' : 'application/json, */*' }
@@ -161,7 +161,7 @@ def call(
161161 log_context .method .set (method )
162162 log_context .url .set (url )
163163
164- self .stats .calls += 1
164+ self ._statistics .calls += 1
165165
166166 headers , params , content = self ._prepare_request_call (headers , params , data , json )
167167
@@ -171,11 +171,13 @@ def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response:
171171 log_context .attempt .set (attempt )
172172 logger .debug ('Sending request' )
173173
174- self .stats .requests += 1
174+ self ._statistics .requests += 1
175175
176176 try :
177177 # Increase timeout with each attempt. Max timeout is bounded by the client timeout.
178- timeout = min (self .config .timeout_secs , (timeout_secs or self .config .timeout_secs ) * 2 ** (attempt - 1 ))
178+ timeout = min (
179+ self ._config .timeout_secs , (timeout_secs or self ._config .timeout_secs ) * 2 ** (attempt - 1 )
180+ )
179181
180182 url_with_params = self ._build_url_with_params (url , params )
181183
@@ -195,7 +197,7 @@ def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response:
195197 return response
196198
197199 if response .status_code == HTTPStatus .TOO_MANY_REQUESTS :
198- self .stats .add_rate_limit_error (attempt )
200+ self ._statistics .add_rate_limit_error (attempt )
199201
200202 except Exception as exc :
201203 logger .debug ('Request threw exception' , exc_info = exc )
@@ -217,8 +219,8 @@ def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response:
217219
218220 return retry_with_exp_backoff (
219221 _make_request ,
220- max_retries = self .config .max_retries ,
221- backoff_base_millis = self .config .min_delay_between_retries_millis ,
222+ max_retries = self ._config .max_retries ,
223+ backoff_base_millis = self ._config .min_delay_between_retries_millis ,
222224 backoff_factor = DEFAULT_BACKOFF_EXPONENTIAL_FACTOR ,
223225 random_factor = DEFAULT_BACKOFF_RANDOM_FACTOR ,
224226 )
@@ -240,7 +242,7 @@ async def call(
240242 log_context .method .set (method )
241243 log_context .url .set (url )
242244
243- self .stats .calls += 1
245+ self ._statistics .calls += 1
244246
245247 headers , params , content = self ._prepare_request_call (headers , params , data , json )
246248
@@ -251,7 +253,9 @@ async def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response
251253 logger .debug ('Sending request' )
252254 try :
253255 # Increase timeout with each attempt. Max timeout is bounded by the client timeout.
254- timeout = min (self .config .timeout_secs , (timeout_secs or self .config .timeout_secs ) * 2 ** (attempt - 1 ))
256+ timeout = min (
257+ self ._config .timeout_secs , (timeout_secs or self ._config .timeout_secs ) * 2 ** (attempt - 1 )
258+ )
255259
256260 url_with_params = self ._build_url_with_params (url , params )
257261
@@ -271,7 +275,7 @@ async def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response
271275 return response
272276
273277 if response .status_code == HTTPStatus .TOO_MANY_REQUESTS :
274- self .stats .add_rate_limit_error (attempt )
278+ self ._statistics .add_rate_limit_error (attempt )
275279
276280 except Exception as exc :
277281 logger .debug ('Request threw exception' , exc_info = exc )
@@ -293,8 +297,8 @@ async def _make_request(stop_retrying: Callable, attempt: int) -> impit.Response
293297
294298 return await retry_with_exp_backoff_async (
295299 _make_request ,
296- max_retries = self .config .max_retries ,
297- backoff_base_millis = self .config .min_delay_between_retries_millis ,
300+ max_retries = self ._config .max_retries ,
301+ backoff_base_millis = self ._config .min_delay_between_retries_millis ,
298302 backoff_factor = DEFAULT_BACKOFF_EXPONENTIAL_FACTOR ,
299303 random_factor = DEFAULT_BACKOFF_RANDOM_FACTOR ,
300304 )
0 commit comments