Skip to content

Commit 80b3e53

Browse files
committed
Add ratelimit stubs
1 parent 49afeeb commit 80b3e53

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

‎stubs/ratelimit/METADATA.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "2.2.*"
2+
upstream_repository = "https://github.com/tomasbasham/ratelimit"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from ratelimit.decorators import RateLimitDecorator, sleep_and_retry
2+
from ratelimit.exception import RateLimitException
3+
4+
limits = RateLimitDecorator
5+
rate_limited = RateLimitDecorator
6+
7+
__all__ = ["RateLimitException", "limits", "rate_limited", "sleep_and_retry"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from collections.abc import Callable
2+
from typing import TypeVar
3+
from typing_extensions import ParamSpec
4+
5+
_P = ParamSpec("_P")
6+
_T = TypeVar("_T")
7+
8+
now: Callable[[], float] = ...
9+
10+
class RateLimitDecorator:
11+
def __init__(
12+
self, calls: int = ..., period: float = ..., clock: Callable[[], float] = ..., raise_on_limit: bool = ...
13+
) -> None: ...
14+
def __call__(self, func: Callable[_P, _T]) -> Callable[_P, _T]: ...
15+
16+
def sleep_and_retry(func: Callable[_P, _T]) -> Callable[_P, _T]: ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class RateLimitException(Exception):
2+
period_remaining: float
3+
def __init__(self, message: str, period_remaining: float) -> None: ...

0 commit comments

Comments
 (0)