Skip to content

Commit f28a4c8

Browse files
committed
fix(api): resolve ruff lint errors
- Fix import sorting and unused imports - Remove duplicate abstract method definitions in AIProvider - Replace try-except-pass with contextlib.suppress in telemetry - Prefix unused variable with underscore in rate_limit - Add noqa comments for Pydantic/ABC Generic compatibility (UP046) - Add noqa for local dev default password (S105)
1 parent 11ef628 commit f28a4c8

File tree

10 files changed

+21
-33
lines changed

10 files changed

+21
-33
lines changed

apps/api/alembic/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import asyncio
22
from logging.config import fileConfig
33

4-
from alembic import context
54
from sqlalchemy import pool
65
from sqlalchemy.engine import Connection
76
from sqlalchemy.ext.asyncio import async_engine_from_config
87

8+
from alembic import context
99
from src.lib.config import settings
1010
from src.lib.database import Base
1111

apps/api/src/common/models/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
)
99

1010
__all__ = [
11-
"TimestampMixin",
12-
"UUIDMixin",
1311
"PaginatedResponse",
1412
"PaginationMeta",
1513
"PaginationParams",
14+
"TimestampMixin",
15+
"UUIDMixin",
1616
]

apps/api/src/common/models/pagination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PaginationMeta(BaseModel):
3030
has_prev: bool = Field(description="Whether there is a previous page")
3131

3232

33-
class PaginatedResponse(BaseModel, Generic[T]):
33+
class PaginatedResponse(BaseModel, Generic[T]): # noqa: UP046
3434
"""Generic paginated response wrapper."""
3535

3636
data: list[T]

apps/api/src/lib/ai/base.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
from abc import ABC, abstractmethod
2-
from typing import Any, AsyncIterator, Generic, TypeVar
2+
from collections.abc import AsyncIterator
3+
from typing import Any, Generic, TypeVar
34

45
T = TypeVar("T")
56

67

7-
class AIProvider(ABC, Generic[T]):
8+
class AIProvider(ABC, Generic[T]): # noqa: UP046
89
@abstractmethod
910
async def analyze_image(self, image_data: bytes | list[bytes]) -> T:
1011
pass
1112

12-
@abstractmethod
13-
async def generate_text(self, prompt: str, **kwargs: Any) -> str:
14-
pass
15-
16-
@abstractmethod
17-
async def generate_stream(self, prompt: str, **kwargs: Any) -> AsyncIterator[str]:
18-
pass
19-
20-
@abstractmethod
21-
async def generate_structured(
22-
self, prompt: str, schema: type[T], **kwargs: Any
23-
) -> T:
24-
pass
25-
2613
@abstractmethod
2714
async def generate_text(self, prompt: str, **kwargs: Any) -> str:
2815
"""Generate text from prompt.

apps/api/src/lib/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Callable
22
from functools import wraps
3-
from typing import Annotated, Any, Literal
3+
from typing import Annotated, Any
44

55
import httpx
66
from fastapi import Depends, HTTPException, Request, status

apps/api/src/lib/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Settings(BaseSettings):
4646
GCS_BUCKET_NAME: str | None = None
4747
MINIO_ENDPOINT: str = "localhost:9000"
4848
MINIO_ACCESS_KEY: str = "minioadmin"
49-
MINIO_SECRET_KEY: str = "minioadmin"
49+
MINIO_SECRET_KEY: str = "minioadmin" # noqa: S105
5050

5151

5252
@lru_cache

apps/api/src/lib/dependencies.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222

2323
# Re-export auth dependencies for convenience
2424
__all__ = [
25-
"DBSession",
2625
"CurrentUser",
26+
"DBSession",
27+
"OptionalSession",
2728
"OptionalUser",
2829
"RequiredSession",
29-
"OptionalSession",
30-
"SessionUser",
3130
"SessionResponse",
31+
"SessionUser",
3232
"get_current_user",
33+
"get_optional_session",
3334
"get_optional_user",
3435
"get_required_session",
35-
"get_optional_session",
3636
]

apps/api/src/lib/rate_limit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import time
44
from collections import defaultdict
5+
from collections.abc import Callable
56
from dataclasses import dataclass, field
6-
from typing import Callable
77

88
from fastapi import HTTPException, Request, status
99

@@ -180,9 +180,9 @@ async def wrapper(*args, **kwargs):
180180
key = actual_key_func(request)
181181

182182
if isinstance(limiter, RedisRateLimiter):
183-
allowed, remaining, reset_after = await limiter.is_allowed(key)
183+
allowed, _remaining, reset_after = await limiter.is_allowed(key)
184184
else:
185-
allowed, remaining, reset_after = limiter.is_allowed(key)
185+
allowed, _remaining, reset_after = limiter.is_allowed(key)
186186

187187
if not allowed:
188188
logger.warning("Rate limit exceeded", key=key)

apps/api/src/lib/telemetry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""OpenTelemetry configuration for distributed tracing."""
22

3+
import contextlib
4+
35
from opentelemetry import trace
46
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
57
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
@@ -60,10 +62,8 @@ def instrument_app(app: "FastAPI") -> None: # noqa: F821
6062
HTTPXClientInstrumentor().instrument()
6163

6264
# Instrument Redis (if available)
63-
try:
65+
with contextlib.suppress(Exception):
6466
RedisInstrumentor().instrument()
65-
except Exception:
66-
pass # Redis not installed or not configured
6767

6868

6969
def get_tracer(name: str = __name__) -> trace.Tracer:

apps/api/src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import AsyncIterator
12
from contextlib import asynccontextmanager
2-
from typing import AsyncIterator, Literal
3+
from typing import Literal
34
from uuid import uuid4
45

56
import structlog

0 commit comments

Comments
 (0)