diff --git a/rate_limited/calls.py b/rate_limited/calls.py index b626e36..d843a46 100644 --- a/rate_limited/calls.py +++ b/rate_limited/calls.py @@ -3,6 +3,8 @@ from inspect import signature from typing import Any, Callable, List +Result = Any + @dataclass class Call: @@ -10,7 +12,7 @@ class Call: args: tuple kwargs: dict num_retries: int = 0 - result: Any = None + result: Result = None exceptions: List[Exception] = field(default_factory=list) @cached_property diff --git a/rate_limited/resources.py b/rate_limited/resources.py index b1c9c67..cd4d8c5 100644 --- a/rate_limited/resources.py +++ b/rate_limited/resources.py @@ -1,9 +1,9 @@ from collections import deque from dataclasses import dataclass from datetime import datetime, timedelta -from typing import Any, Callable, Optional +from typing import Callable, Optional -from rate_limited.calls import Call +from rate_limited.calls import Call, Result Unit = float @@ -21,7 +21,7 @@ def __init__( quota: Unit, time_window_seconds: float, arguments_usage_extractor: Optional[Callable[[Call], Unit]] = None, - results_usage_extractor: Optional[Callable[[Any], Unit]] = None, + results_usage_extractor: Optional[Callable[[Result], Unit]] = None, max_results_usage_estimator: Optional[Callable[[Call], Unit]] = None, ): """ diff --git a/rate_limited/runner.py b/rate_limited/runner.py index f6d706e..ae119d4 100644 --- a/rate_limited/runner.py +++ b/rate_limited/runner.py @@ -5,9 +5,9 @@ from concurrent.futures import ThreadPoolExecutor from inspect import signature from logging import getLogger -from typing import Any, Callable, Collection, List, Optional, Tuple +from typing import Callable, Collection, List, Optional, Tuple -from rate_limited.calls import Call +from rate_limited.calls import Call, Result from rate_limited.exceptions import ValidationError from rate_limited.progress_bar import ProgressBar from rate_limited.queue import CompletionTrackingQueue @@ -23,7 +23,7 @@ def __init__( resources: Collection[Resource], max_concurrent: int, max_retries: int = 5, - validation_function: Optional[Callable[[Any], bool]] = None, + validation_function: Optional[Callable[[Result], bool]] = None, progress_interval: float = 1.0, long_wait_warning_seconds: Optional[float] = 2.0, ):