Skip to content

Commit

Permalink
fix: providing remaining always raises ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRPS committed Jan 7, 2024
1 parent 3376bfa commit f413d19
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions discord/rate_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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
Expand All @@ -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"
)
Expand Down

0 comments on commit f413d19

Please sign in to comment.