Skip to content

Add ratelimit stubs #13909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stubs/ratelimit/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This file lacks __all__ and "now" is only used to set the default value of
# RateLimitDecorator.__init__()'s clock parameter
ratelimit.decorators.now
2 changes: 2 additions & 0 deletions stubs/ratelimit/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "2.2.*"
upstream_repository = "https://github.com/tomasbasham/ratelimit"
7 changes: 7 additions & 0 deletions stubs/ratelimit/ratelimit/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ratelimit.decorators import RateLimitDecorator, sleep_and_retry
from ratelimit.exception import RateLimitException

limits = RateLimitDecorator
rate_limited = RateLimitDecorator

__all__ = ["RateLimitException", "limits", "rate_limited", "sleep_and_retry"]
14 changes: 14 additions & 0 deletions stubs/ratelimit/ratelimit/decorators.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from collections.abc import Callable
from typing import TypeVar
from typing_extensions import ParamSpec

_P = ParamSpec("_P")
_T = TypeVar("_T")

class RateLimitDecorator:
def __init__(
self, calls: int = 15, period: float = 900, clock: Callable[[], float] = ..., raise_on_limit: bool = True
) -> None: ...
def __call__(self, func: Callable[_P, _T]) -> Callable[_P, _T]: ...

def sleep_and_retry(func: Callable[_P, _T]) -> Callable[_P, _T]: ...
3 changes: 3 additions & 0 deletions stubs/ratelimit/ratelimit/exception.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class RateLimitException(Exception):
period_remaining: float
def __init__(self, message: str, period_remaining: float) -> None: ...