Skip to content

Commit 50bf63c

Browse files
committed
chore(ci): fix lint/type issues blocking pipeline
1 parent efc27d8 commit 50bf63c

9 files changed

Lines changed: 30 additions & 21 deletions

File tree

app/logging_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import logging
1212
import sys
1313
from contextvars import ContextVar
14-
from typing import Any
14+
from typing import Any, cast
1515

1616
import structlog
1717

@@ -50,7 +50,7 @@ def configure_logging(
5050
logger.info("Application started", version="1.0.0")
5151
"""
5252
# Shared processors for all log entries
53-
shared_processors: list[structlog.types.Processor] = [
53+
shared_processors: list[Any] = [
5454
structlog.contextvars.merge_contextvars,
5555
structlog.stdlib.add_logger_name,
5656
structlog.stdlib.add_log_level,
@@ -127,7 +127,7 @@ def get_logger(name: str | None = None) -> structlog.stdlib.BoundLogger:
127127
logger.info("Processing query", query="SELECT * FROM users")
128128
logger.error("Query failed", error="Connection timeout", retry_count=3)
129129
"""
130-
return structlog.get_logger(name)
130+
return cast(structlog.stdlib.BoundLogger, structlog.get_logger(name))
131131

132132

133133
class LogContext:

app/middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import time
1313
import uuid
1414
from collections.abc import Callable
15-
from typing import Any
15+
from typing import Any, cast
1616

1717
from fastapi import FastAPI, HTTPException, Request, Response
1818
from fastapi.middleware.cors import CORSMiddleware
@@ -69,7 +69,7 @@ async def dispatch(
6969
# Add request ID to response headers
7070
response.headers["X-Request-ID"] = request_id
7171

72-
return response
72+
return cast(Response, response)
7373

7474
except Exception as e:
7575
duration_ms = (time.perf_counter() - start_time) * 1000
@@ -214,8 +214,8 @@ def setup_middleware(app: FastAPI, cors_origins: list[str] | None = None) -> Non
214214
app.add_middleware(RequestLoggingMiddleware)
215215

216216
# Exception handlers
217-
app.add_exception_handler(Text2SQLException, exception_handler)
218-
app.add_exception_handler(HTTPException, http_exception_handler)
217+
app.add_exception_handler(Text2SQLException, exception_handler) # type: ignore[arg-type]
218+
app.add_exception_handler(HTTPException, http_exception_handler) # type: ignore[arg-type]
219219
app.add_exception_handler(Exception, generic_exception_handler)
220220

221221
logger.info(

app/resilience.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,5 @@ def compute_backoff_seconds(
161161
Returns:
162162
Backoff delay in seconds.
163163
"""
164-
delay = base_seconds * (2**attempt)
165-
return min(delay, max_seconds)
164+
delay = float(base_seconds * (2**attempt))
165+
return float(min(delay, max_seconds))

app/security/headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from collections.abc import Callable
12-
from typing import Any
12+
from typing import Any, cast
1313

1414
from fastapi import Request, Response
1515
from starlette.middleware.base import BaseHTTPMiddleware
@@ -80,4 +80,4 @@ async def dispatch(
8080
if "X-Powered-By" in response.headers:
8181
del response.headers["X-Powered-By"]
8282

83-
return response
83+
return cast(Response, response)

app/security/rate_limiting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def setup_rate_limiting(app: FastAPI) -> None:
7979
>>> setup_rate_limiting(app)
8080
"""
8181
app.state.limiter = limiter
82-
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
82+
app.add_exception_handler(
83+
RateLimitExceeded, _rate_limit_exceeded_handler # type: ignore[arg-type]
84+
)
8385

8486
logger.info(
8587
"rate_limiting_configured",

app/text2sql_engine.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,14 @@ async def _run_inference(use_examples: bool) -> InferenceResult:
853853
for attempt in range(self._max_retries):
854854
try:
855855
use_examples = attempt > 0 # Add examples on retry
856-
result = await self._circuit_breaker.run(
857-
lambda use_examples=use_examples: _run_inference(use_examples)
858-
)
856+
current_use_examples = use_examples
857+
858+
async def _task(
859+
use_examples: bool = current_use_examples,
860+
) -> InferenceResult:
861+
return await _run_inference(use_examples)
862+
863+
result = await self._circuit_breaker.run(_task)
859864

860865
if best_result is None or result.confidence > best_result.confidence:
861866
best_result = result

db/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def execute(
248248
)
249249

250250
result.execution_time_ms = execution_time_ms
251-
return result # type: ignore[no-any-return]
251+
return result
252252

253253
except asyncio.TimeoutError as e:
254254
logger.error(
@@ -274,7 +274,7 @@ async def execute(
274274
details={"error": str(e)},
275275
) from e
276276

277-
@retry( # type: ignore[untyped-decorator]
277+
@retry(
278278
retry=retry_if_exception_type((ConnectionError, OSError)),
279279
stop=stop_after_attempt(3),
280280
wait=wait_exponential(multiplier=1, min=2, max=10),

models/inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async def generate(
266266

267267
# Generate
268268
with torch.no_grad():
269-
outputs = self.model.generate(
269+
outputs = self.model.generate( # type: ignore[operator]
270270
**inputs,
271271
**config.to_dict(),
272272
return_dict_in_generate=True,

models/loader.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import gc
1212
from dataclasses import dataclass
13-
from typing import Any
13+
from typing import Any, cast
1414

1515
import torch
1616
from transformers import (
@@ -290,7 +290,9 @@ async def _load_model(self) -> PreTrainedModel:
290290

291291
# Move to device if not using device_map
292292
if "device_map" not in load_kwargs:
293-
model = model.to(device)
293+
model = cast(
294+
PreTrainedModel, model.to(device) # type: ignore[arg-type,assignment]
295+
)
294296

295297
# Set to evaluation mode
296298
model.eval()
@@ -328,7 +330,7 @@ async def warmup(self, sample_text: str = "SELECT * FROM users") -> None:
328330
inputs = {k: v.to(device) for k, v in inputs.items()}
329331

330332
with torch.no_grad():
331-
_ = self._model.generate(
333+
_ = self._model.generate( # type: ignore[operator]
332334
**inputs,
333335
max_new_tokens=10,
334336
do_sample=False,

0 commit comments

Comments
 (0)