From 5368dbf8a4df2bbb063f9b87a302c1d2c2bc3932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 9 Apr 2026 12:47:43 +0200 Subject: [PATCH 1/2] refact: reorder if clause doc: type hinting --- src/omnia_timeseries/helpers.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/omnia_timeseries/helpers.py b/src/omnia_timeseries/helpers.py index ae2385e..f459cb7 100644 --- a/src/omnia_timeseries/helpers.py +++ b/src/omnia_timeseries/helpers.py @@ -1,12 +1,19 @@ from functools import wraps +import logging import time +from typing import Optional from omnia_timeseries.models import TimeseriesRequestFailedException # Reasonable status codes to retry, based on descriptions at https://en.wikipedia.org/wiki/List_of_HTTP_status_codes retry_status_codes = [408, 409, 425, 429, 502, 503, 504] -def retry(total_tries=3, initial_wait=0.5, backoff_factor=2, logger=None): +def retry( + total_tries=3, + initial_wait=0.5, + backoff_factor=2, + logger: Optional[logging.Logger] = None, +): def retry_decorator(f): @wraps(f) def func_with_retries(*args, **kwargs): @@ -20,18 +27,16 @@ def func_with_retries(*args, **kwargs): except TimeseriesRequestFailedException as e: _tries -= 1 if e.status_code in retry_status_codes: - if _tries == 0: - msg = str( - f"Function: {f.__name__} Failed despite best efforts after {total_tries} tries." - ) - if logger is not None: - logger.warning(msg) - else: - msg = str( - f"Function: {f.__name__} failed with {e}. Retrying in {_delay} seconds, with {_tries} retries remaining!\n" - ) - if logger is not None: - logger.warning(msg) + if logger is not None: + if _tries == 0: + msg = str( + f"Function: {f.__name__} Failed despite best efforts after {total_tries} tries." + ) + else: + msg = str( + f"Function: {f.__name__} failed with {e}. Retrying in {_delay} seconds, with {_tries} retries remaining!\n" + ) + logger.warning(msg) time.sleep(_delay) _delay *= backoff_factor exception = e From e07a51e499ffdf3894277176b4e854f5e439e6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Sun, 31 May 2026 17:44:53 +0200 Subject: [PATCH 2/2] refact: string(f-string(...)) -> f-string(...) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/omnia_timeseries/helpers.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/omnia_timeseries/helpers.py b/src/omnia_timeseries/helpers.py index f459cb7..b7a18cc 100644 --- a/src/omnia_timeseries/helpers.py +++ b/src/omnia_timeseries/helpers.py @@ -29,13 +29,9 @@ def func_with_retries(*args, **kwargs): if e.status_code in retry_status_codes: if logger is not None: if _tries == 0: - msg = str( - f"Function: {f.__name__} Failed despite best efforts after {total_tries} tries." - ) + msg = f"Function: {f.__name__} Failed despite best efforts after {total_tries} tries." else: - msg = str( - f"Function: {f.__name__} failed with {e}. Retrying in {_delay} seconds, with {_tries} retries remaining!\n" - ) + msg = f"Function: {f.__name__} failed with {e}. Retrying in {_delay} seconds, with {_tries} retries remaining!" logger.warning(msg) time.sleep(_delay) _delay *= backoff_factor