mirror of
https://github.com/laurentS/slowapi.git
synced 2026-03-13 09:10:20 +08:00
🏷️ resolve mypy errors and add mypy_cache to gitignore
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,5 +1,9 @@
|
||||
# testing
|
||||
.pytest_cache
|
||||
__pycache__
|
||||
|
||||
# typing
|
||||
.mypy_cache
|
||||
|
||||
# editors
|
||||
.idea
|
||||
|
||||
@@ -269,7 +269,7 @@ class Limiter:
|
||||
if not self._application_limits and app_limits:
|
||||
self._application_limits = [
|
||||
LimitGroup(
|
||||
app_limits, self._key_func, "global", False, None, None, None
|
||||
app_limits, self._key_func, "global", False, None, None, None, False
|
||||
)
|
||||
]
|
||||
|
||||
@@ -278,7 +278,9 @@ class Limiter:
|
||||
)
|
||||
if not self._default_limits and conf_limits:
|
||||
self._default_limits = [
|
||||
LimitGroup(conf_limits, self._key_func, None, False, None, None, None)
|
||||
LimitGroup(
|
||||
conf_limits, self._key_func, None, False, None, None, None, False
|
||||
)
|
||||
]
|
||||
fallback_enabled = self.get_app_config(C.IN_MEMORY_FALLBACK_ENABLED, False)
|
||||
fallback_limits: Optional[StrOrCallableStr] = self.get_app_config(
|
||||
@@ -287,7 +289,14 @@ class Limiter:
|
||||
if not self._in_memory_fallback and fallback_limits:
|
||||
self._in_memory_fallback = [
|
||||
LimitGroup(
|
||||
fallback_limits, self._key_func, None, False, None, None, None
|
||||
fallback_limits,
|
||||
self._key_func,
|
||||
None,
|
||||
False,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
False,
|
||||
)
|
||||
]
|
||||
if not self._in_memory_fallback_enabled:
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Union
|
||||
|
||||
from starlette.applications import Starlette
|
||||
from starlette.middleware.base import (
|
||||
BaseHTTPMiddleware,
|
||||
@@ -6,6 +8,7 @@ from starlette.middleware.base import (
|
||||
)
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
from starlette.routing import Route, BaseRoute, WebSocketRoute
|
||||
|
||||
from slowapi import Limiter, _rate_limit_exceeded_handler
|
||||
|
||||
@@ -19,8 +22,8 @@ class SlowAPIMiddleware(BaseHTTPMiddleware):
|
||||
handler = None
|
||||
for route in app.routes:
|
||||
match, _ = route.matches(request.scope)
|
||||
if match.FULL:
|
||||
handler = route.endpoint
|
||||
if match.FULL and hasattr(route, "endpoint"):
|
||||
handler = route.endpoint # type: ignore
|
||||
# if we can't find the route handler
|
||||
if handler is None:
|
||||
return await call_next(request)
|
||||
@@ -50,3 +53,4 @@ class SlowAPIMiddleware(BaseHTTPMiddleware):
|
||||
response = await call_next(request)
|
||||
response = limiter._inject_headers(response, request.state.view_rate_limit)
|
||||
return response
|
||||
return await call_next(request)
|
||||
|
||||
Reference in New Issue
Block a user