style: apply ruff's automatic fixes and formatter
Mechanical only, and separated from the judgment calls that follow so the reviewable changes are not buried in a 98-file whitespace diff. 227 automatic fixes: 60 blank lines carrying whitespace, 60 unsorted import blocks, 34 Optional[X] to X | None, 28 unused imports, 16 deprecated typing imports, 12 datetime.timezone.utc to datetime.UTC, and assorted smaller modernisations. Then `ruff format` over src and tests: 98 files reformatted, 35 already conforming. No file among the unused-import findings defines __all__ or is an __init__.py, so nothing here removes a re-export. `make test`: 658 passed, unchanged from HEAD. Two things observed while verifying, neither addressed here: `pytest tests/` cannot collect — tests/e2e/test_orchestration_e2e.py uses an `e2e` marker that is not registered, and the config is strict about markers. This fails identically at HEAD, so it predates this change; `make test` passes because it ignores tests/e2e, tests/integration and tests/contracts. test_tatlock_tool_call_logging_calculator is flaky. It failed once in a full run with these changes and passed on the next, passes in isolation with them, and fails in isolation at HEAD. It is order- or timing-dependent, not a regression from this commit — established by running the full suite both ways rather than by reasoning about which change could have caused it. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+8
-7
@@ -9,8 +9,9 @@ Main responsibilities:
|
||||
- Router registration
|
||||
- Lifecycle management
|
||||
"""
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import AsyncGenerator
|
||||
|
||||
from fastapi import FastAPI, Request, status
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
@@ -64,7 +65,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
def create_application() -> FastAPI:
|
||||
"""
|
||||
Application factory.
|
||||
|
||||
|
||||
Creates and configures the FastAPI application.
|
||||
Following best practice of using factory pattern.
|
||||
"""
|
||||
@@ -75,7 +76,7 @@ def create_application() -> FastAPI:
|
||||
lifespan=lifespan,
|
||||
debug=config.DEBUG,
|
||||
)
|
||||
|
||||
|
||||
# Add middleware
|
||||
application.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -84,10 +85,10 @@ def create_application() -> FastAPI:
|
||||
allow_methods=config.CORS_ALLOW_METHODS,
|
||||
allow_headers=config.CORS_ALLOW_HEADERS,
|
||||
)
|
||||
|
||||
|
||||
# Register exception handlers
|
||||
register_exception_handlers(application)
|
||||
|
||||
|
||||
# Include routers
|
||||
application.include_router(core_router) # Health and root endpoints
|
||||
application.include_router(chat_router, prefix=config.API_PREFIX)
|
||||
@@ -105,10 +106,10 @@ def create_application() -> FastAPI:
|
||||
def register_exception_handlers(application: FastAPI) -> None:
|
||||
"""
|
||||
Register global exception handlers.
|
||||
|
||||
|
||||
Provides consistent error responses compatible with OpenAI API.
|
||||
"""
|
||||
|
||||
|
||||
@application.exception_handler(AppException)
|
||||
async def app_exception_handler(
|
||||
request: Request,
|
||||
|
||||
Reference in New Issue
Block a user