@@ -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 )
0 commit comments