Skip to content

Commit eec809d

Browse files
authored
Add ratelimit stubs (#13909)
1 parent dd4ef75 commit eec809d

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file lacks __all__ and "now" is only used to set the default value of
2+
# RateLimitDecorator.__init__()'s clock parameter
3+
ratelimit.decorators.now

stubs/ratelimit/METADATA.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "2.2.*"
2+
upstream_repository = "https://github.com/tomasbasham/ratelimit"
+7
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"]
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
class RateLimitDecorator:
9+
def __init__(
10+
self, calls: int = 15, period: float = 900, clock: Callable[[], float] = ..., raise_on_limit: bool = True
11+
) -> None: ...
12+
def __call__(self, func: Callable[_P, _T]) -> Callable[_P, _T]: ...
13+
14+
def sleep_and_retry(func: Callable[_P, _T]) -> Callable[_P, _T]: ...
+3
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)