style: clean up unused parameters and imports in examples

This commit is contained in:
2026-02-04 01:08:16 +00:00
parent 6bc108078f
commit d7966f7e96
11 changed files with 143 additions and 95 deletions

View File

@@ -9,8 +9,8 @@ from fastapi.responses import JSONResponse
from fastapi_traffic import (
MemoryBackend,
RateLimitExceeded,
RateLimiter,
RateLimitExceeded,
rate_limit,
)
from fastapi_traffic.core.limiter import set_limiter
@@ -21,7 +21,7 @@ limiter = RateLimiter(backend)
@asynccontextmanager
async def lifespan(app: FastAPI):
async def lifespan(_: FastAPI):
"""Lifespan context manager for startup/shutdown."""
await limiter.initialize()
set_limiter(limiter)
@@ -34,7 +34,7 @@ app = FastAPI(title="Quickstart Example", lifespan=lifespan)
# Step 2: Add exception handler for rate limit errors
@app.exception_handler(RateLimitExceeded)
async def rate_limit_handler(request: Request, exc: RateLimitExceeded) -> JSONResponse:
async def rate_limit_handler(_: Request, exc: RateLimitExceeded) -> JSONResponse:
return JSONResponse(
status_code=429,
content={"error": "Too many requests", "retry_after": exc.retry_after},
@@ -44,17 +44,17 @@ async def rate_limit_handler(request: Request, exc: RateLimitExceeded) -> JSONRe
# Step 3: Apply rate limiting to endpoints
@app.get("/")
@rate_limit(10, 60) # 10 requests per minute
async def hello(request: Request) -> dict[str, str]:
async def hello(_: Request) -> dict[str, str]:
return {"message": "Hello, World!"}
@app.get("/api/data")
@rate_limit(100, 60) # 100 requests per minute
async def get_data(request: Request) -> dict[str, str]:
async def get_data(_: Request) -> dict[str, str]:
return {"data": "Some important data"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="127.0.0.1", port=8002)