From f413d19bdc5f2b7fd3153e4091ebb92f28a177ba Mon Sep 17 00:00:00 2001 From: VincentRPS Date: Sun, 7 Jan 2024 11:47:21 +0800 Subject: [PATCH] fix: providing `remaining` always raises ValueError --- discord/rate_limiting.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/discord/rate_limiting.py b/discord/rate_limiting.py index 0180798cc9..5d4f688eb6 100644 --- a/discord/rate_limiting.py +++ b/discord/rate_limiting.py @@ -47,9 +47,10 @@ class GlobalRateLimit: The concurrency to reset every `per` seconds. per: :class:`float` Number of seconds to wait until resetting `concurrency`. - remaining: :class:`int` + remaining: Optional[:class:`int`] Number of available requests remaining. If the value of remaining is larger than concurrency a `ValueError` will be raised. + Defaults to ``None`` Attributes ---------- @@ -61,8 +62,8 @@ class GlobalRateLimit: Unix timestamp of when this class will next reset. """ - def __init__(self, concurrency: int, per: float, remaining: int = MISSING) -> None: - self.concurrency: int = concurrency + def __init__(self, concurrency: int, per: float, remaining: int | None = None) -> None: + self.concurrency: int = remaining or concurrency self.per: float = per self.current: int = self.concurrency @@ -71,7 +72,7 @@ def __init__(self, concurrency: int, per: float, remaining: int = MISSING) -> No self.pending_reset: bool = False self.reset_at: float | None = None - if remaining is not MISSING: + if remaining is not None and remaining > concurrency: raise ValueError( "Given rate limit remaining value is larger than concurrency limit" )