Skip to content

Commit

Permalink
refactor: defining Result as a type
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietruszka committed Aug 17, 2023
1 parent 6871857 commit 346bbf5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion rate_limited/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
from inspect import signature
from typing import Any, Callable, List

Result = Any


@dataclass
class Call:
function: Callable
args: tuple
kwargs: dict
num_retries: int = 0
result: Any = None
result: Result = None
exceptions: List[Exception] = field(default_factory=list)

@cached_property
Expand Down
6 changes: 3 additions & 3 deletions rate_limited/resources.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,
):
"""
Expand Down
6 changes: 3 additions & 3 deletions rate_limited/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
):
Expand Down

0 comments on commit 346bbf5

Please sign in to comment.