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

@@ -11,8 +11,8 @@ from fastapi.responses import JSONResponse
from fastapi_traffic import (
MemoryBackend,
RateLimitExceeded,
RateLimiter,
RateLimitExceeded,
SQLiteBackend,
rate_limit,
)
@@ -32,9 +32,10 @@ def get_backend():
# Redis - Required for distributed/multi-instance deployments
# Requires: pip install redis
try:
from fastapi_traffic import RedisBackend
import asyncio
from fastapi_traffic import RedisBackend
async def create_redis():
return await RedisBackend.from_url(
os.getenv("REDIS_URL", "redis://localhost:6379/0"),
@@ -56,7 +57,7 @@ limiter = RateLimiter(backend)
@asynccontextmanager
async def lifespan(app: FastAPI):
async def lifespan(_: FastAPI):
await limiter.initialize()
set_limiter(limiter)
yield
@@ -67,7 +68,7 @@ app = FastAPI(title="Storage Backends Example", lifespan=lifespan)
@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": "rate_limit_exceeded", "retry_after": exc.retry_after},
@@ -76,7 +77,7 @@ async def rate_limit_handler(request: Request, exc: RateLimitExceeded) -> JSONRe
@app.get("/api/resource")
@rate_limit(100, 60)
async def get_resource(request: Request) -> dict[str, str]:
async def get_resource(_: Request) -> dict[str, str]:
return {"message": "Resource data", "backend": type(backend).__name__}