[pre-commit.ci lite] apply automatic fixes

This commit is contained in:
pre-commit-ci-lite[bot] 2025-11-25 16:44:36 +00:00 committed by GitHub
parent 20fd9130b7
commit d713dc55e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 6 deletions

View file

@ -1,9 +1,9 @@
from __future__ import annotations from __future__ import annotations
from collections import defaultdict, deque from collections import defaultdict
from collections import deque
from threading import Lock from threading import Lock
from time import monotonic from time import monotonic
from typing import Deque, DefaultDict, Tuple
__all__ = ("MemoryRateLimiter",) __all__ = ("MemoryRateLimiter",)
@ -24,10 +24,10 @@ class MemoryRateLimiter:
self.limit = limit self.limit = limit
self.window = window self.window = window
self._requests: DefaultDict[str, Deque[float]] = defaultdict(deque) self._requests: defaultdict[str, deque[float]] = defaultdict(deque)
self._lock = Lock() self._lock = Lock()
def hit(self, key: str) -> Tuple[bool, float | None]: def hit(self, key: str) -> tuple[bool, float | None]:
"""Record a hit for *key*. """Record a hit for *key*.
Returns a tuple ``(allowed, retry_after)`` where *allowed* indicates if Returns a tuple ``(allowed, retry_after)`` where *allowed* indicates if
@ -51,4 +51,3 @@ class MemoryRateLimiter:
bucket.append(now) bucket.append(now)
return True, None return True, None

View file

@ -34,4 +34,3 @@ def test_rate_limit_blocks_after_threshold():
rv = client.get("/") rv = client.get("/")
assert rv.status_code == 429 assert rv.status_code == 429