Skip to content

Commit 4996e65

Browse files
committed
chore: remove CHANGELOG.md and test files; update skip_limiter decorator for type checking
1 parent 0d64f1f commit 4996e65

File tree

5 files changed

+17
-51
lines changed

5 files changed

+17
-51
lines changed

CHANGELOG.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

fastapi_limiter/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ async def health():
1717
async def wrapper(*args, **kwargs):
1818
return await func(*args, **kwargs)
1919

20-
wrapper._skip_limiter = True
20+
wrapper._skip_limiter = True # type: ignore
2121
return wrapper

fastapi_limiter/depends.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def __init__(
2929

3030
async def _check(self, key: str) -> int:
3131
redis = FastAPILimiter.redis
32-
assert redis is not None
3332
pexpire: int = await redis.evalsha(
3433
FastAPILimiter.lua_sha, 1, key, str(self.times), str(self.milliseconds)
3534
)
@@ -45,10 +44,16 @@ async def __call__(self, request: Request, response: Response):
4544
route_index = 0
4645
dep_index = 0
4746
for i, route in enumerate(request.app.routes):
48-
if route.path == request.scope["path"] and hasattr(route, "methods") and request.method in route.methods:
47+
if (
48+
route.path == request.scope["path"]
49+
and hasattr(route, "methods")
50+
and request.method in route.methods
51+
):
4952
route_index = i
5053
# Check if the route endpoint has _skip_limiter attribute
51-
if hasattr(route, "endpoint") and getattr(route.endpoint, "_skip_limiter", False):
54+
if hasattr(route, "endpoint") and getattr(
55+
route.endpoint, "_skip_limiter", False
56+
):
5257
return
5358
for j, dependency in enumerate(route.dependencies):
5459
if self is dependency.dependency:
@@ -58,8 +63,6 @@ async def __call__(self, request: Request, response: Response):
5863
# moved here because constructor run before app startup
5964
identifier = self.identifier or FastAPILimiter.identifier
6065
callback = self.callback or FastAPILimiter.http_callback
61-
assert identifier is not None
62-
assert callback is not None
6366
rate_key = await identifier(request)
6467
key = f"{FastAPILimiter.prefix}:{rate_key}:{route_index}:{dep_index}"
6568
try:
@@ -81,7 +84,6 @@ async def __call__(self, ws: WebSocket, context_key: str = ""):
8184
"You must call FastAPILimiter.init in startup event of fastapi!"
8285
)
8386
identifier = self.identifier or FastAPILimiter.identifier
84-
assert identifier is not None
8587
rate_key = await identifier(ws)
8688
key = f"{FastAPILimiter.prefix}:ws:{rate_key}:{context_key}"
8789
pexpire = await self._check(key)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ def test_limiter_websockets():
6565
data = ws.receive_text()
6666
assert data == "Hello, world"
6767
ws.close()
68+
69+
70+
def test_skip_limiter():
71+
with TestClient(app) as client:
72+
# Even with RateLimiter(times=1), skip_limiter allows unlimited requests
73+
for _ in range(5):
74+
response = client.get("/skip")
75+
assert response.status_code == 200

tests/test_skip.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)