Skip to content

Commit 4dc83fa

Browse files
committed
fix: resolve ruff lint errors across backend
1 parent 6900557 commit 4dc83fa

File tree

8 files changed

+34
-29
lines changed

8 files changed

+34
-29
lines changed

apps/api/app/api/v1/chat.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
from app.db import get_db
1616
from app.db.tables import Conversation, Message
1717
from app.i18n import get_progress_message, t
18-
from app.models import APIResponse, ChatStopRequest, MessagePaginatedResponse, MessageResponse, SSEEvent
18+
from app.models import (
19+
APIResponse,
20+
ChatStopRequest,
21+
MessagePaginatedResponse,
22+
MessageResponse,
23+
SSEEvent,
24+
)
1925
from app.services.app_settings import get_or_create_app_settings, settings_to_dict
2026
from app.services.chat_runtime import (
2127
ActiveQueryRegistry,

apps/api/app/services/engine_visualization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
from typing import Any
6+
67
import structlog
78

89
logger = structlog.get_logger()

apps/api/app/services/execution.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
使用 gptme 作为执行引擎
44
"""
55

6-
from asyncio import TimeoutError as AsyncioTimeoutError
76
from collections.abc import AsyncGenerator, Callable
87
from dataclasses import dataclass
98
from typing import Any
@@ -280,7 +279,7 @@ async def execute_stream(
280279
failed_stage="execution",
281280
)
282281

283-
except AsyncioTimeoutError as exc:
282+
except TimeoutError:
284283
# Timeout errors - these are expected in some scenarios
285284
logger.warning(
286285
"Timeout during execution",

apps/api/app/services/gptme_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
PythonSecurityAnalyzer,
5555
validate_python_code,
5656
)
57-
from app.services.sql_executor import SQLExecutor
5857
from app.services.python_sandbox import PythonSandbox
5958
from app.services.result_processor import ResultProcessor
59+
from app.services.sql_executor import SQLExecutor
6060
from app.services.visualization_engine import VisualizationEngine
6161

6262
logger = structlog.get_logger()

apps/api/app/services/python_sandbox.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
from __future__ import annotations
99

10-
from typing import TYPE_CHECKING, Any
1110
import asyncio
11+
from typing import TYPE_CHECKING, Any
12+
1213
import structlog
1314

1415
if TYPE_CHECKING:
15-
from app.services.engine_workflow import EngineRunState
16+
pass
1617

1718
logger = structlog.get_logger()
1819

@@ -92,7 +93,7 @@ async def execute(
9293
self._execute_with_timeout(code),
9394
timeout=timeout,
9495
)
95-
except asyncio.TimeoutError as exc:
96+
except TimeoutError as exc:
9697
logger.error("Python execution timeout", timeout=timeout)
9798
raise RuntimeError(f"Code execution timeout ({timeout}s)") from exc
9899

apps/api/app/services/result_processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import annotations
99

1010
from typing import TYPE_CHECKING, Any
11+
1112
import structlog
1213

1314
if TYPE_CHECKING:
@@ -55,9 +56,9 @@ async def extract_results(
5556
ValueError: Content parsing failed (malformed response)
5657
"""
5758
from app.services.engine_content import (
59+
extract_chart_config,
5860
extract_python_block,
5961
extract_sql_block,
60-
extract_chart_config,
6162
parse_thinking_markers,
6263
)
6364

apps/api/app/services/visualization_engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import annotations
99

1010
from typing import TYPE_CHECKING, Any
11+
1112
import structlog
1213

1314
if TYPE_CHECKING:

apps/api/tests/test_services.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
Per BACK-06: Code review and test coverage documentation.
1111
"""
1212

13+
from unittest.mock import MagicMock, patch
14+
1315
import pytest
14-
from unittest.mock import AsyncMock, MagicMock, patch, Mock
15-
from typing import Any
1616

17-
from app.services.sql_executor import SQLExecutor
1817
from app.services.python_sandbox import PythonSandbox
1918
from app.services.result_processor import ResultProcessor
19+
from app.services.sql_executor import SQLExecutor
2020
from app.services.visualization_engine import VisualizationEngine
2121

2222

@@ -236,8 +236,7 @@ async def test_execute_with_timeout(self, sandbox):
236236
mock_runtime_class.return_value = mock_runtime
237237

238238
with patch("asyncio.wait_for") as mock_wait:
239-
import asyncio
240-
mock_wait.side_effect = asyncio.TimeoutError()
239+
mock_wait.side_effect = TimeoutError()
241240

242241
with pytest.raises(RuntimeError) as exc_info:
243242
await sandbox.execute(slow_code, timeout=5)
@@ -398,12 +397,8 @@ async def test_extract_chart_config_valid(self, processor):
398397
"yKeys": ["revenue"],
399398
}
400399

401-
sql_data = [
402-
{"date": "2024-01-01", "revenue": 1000},
403-
{"date": "2024-01-02", "revenue": 2000},
404-
]
405400

406-
result = await processor.extract_results(ai_content)
401+
await processor.extract_results(ai_content)
407402

408403
# Since extract_chart_config is mocked, verify the mock is set up
409404
mock_extract.assert_called()
@@ -428,7 +423,7 @@ def test_build_chart_payload(self, processor):
428423
"data": data,
429424
}
430425

431-
with patch("app.services.engine_visualization.build_chart_from_config", return_value=expected_chart) as mock_build:
426+
with patch("app.services.engine_visualization.build_chart_from_config", return_value=expected_chart):
432427
result = processor.build_chart_payload(chart_config, data)
433428

434429
assert result is not None
@@ -580,7 +575,7 @@ class TestServiceModuleIntegration:
580575
async def test_sql_to_python_pipeline(self):
581576
"""Test pipeline: SQL execution → Python analysis"""
582577
sql_executor = SQLExecutor()
583-
python_sandbox = PythonSandbox()
578+
PythonSandbox()
584579

585580
# Mock SQL execution result
586581
mock_result = MagicMock()
@@ -608,7 +603,7 @@ async def test_sql_to_python_pipeline(self):
608603
async def test_result_processor_to_visualization_pipeline(self):
609604
"""Test pipeline: Result extraction → Chart generation"""
610605
processor = ResultProcessor()
611-
engine = VisualizationEngine()
606+
VisualizationEngine()
612607

613608
ai_content = """
614609
SQL: SELECT category, COUNT(*) as count FROM items GROUP BY category
@@ -646,7 +641,6 @@ async def test_sql_executor_specific_exceptions(self):
646641
executor = SQLExecutor()
647642

648643
# Check that code uses specific exception types
649-
from sqlalchemy.exc import OperationalError, ProgrammingError
650644
import inspect
651645

652646
source = inspect.getsource(executor.execute_sql)
@@ -695,9 +689,9 @@ class TestAPICCompatibility:
695689

696690
def test_service_modules_importable(self):
697691
"""Verify all service modules can be imported"""
698-
from app.services.sql_executor import SQLExecutor
699692
from app.services.python_sandbox import PythonSandbox
700693
from app.services.result_processor import ResultProcessor
694+
from app.services.sql_executor import SQLExecutor
701695
from app.services.visualization_engine import VisualizationEngine
702696

703697
assert SQLExecutor is not None
@@ -707,10 +701,10 @@ def test_service_modules_importable(self):
707701

708702
def test_gptme_engine_imports_services(self):
709703
"""Verify GptmeEngine imports and uses service modules"""
710-
from app.services.gptme_engine import GptmeEngine
711-
712704
import inspect
713705

706+
from app.services.gptme_engine import GptmeEngine
707+
714708
source = inspect.getsource(GptmeEngine)
715709

716710
# Verify service modules are imported
@@ -721,20 +715,22 @@ def test_gptme_engine_imports_services(self):
721715

722716
def test_service_module_type_hints(self):
723717
"""Verify service modules have proper type hints per BACK-06 checklist"""
724-
from app.services.sql_executor import SQLExecutor
725718
import inspect
726719

720+
from app.services.sql_executor import SQLExecutor
721+
727722
# Check type hints on main methods
728723
sig = inspect.signature(SQLExecutor.execute_sql)
729724
assert sig.return_annotation is not None
730725

731726
def test_no_bare_except_clauses(self):
732727
"""Verify no bare except clauses per D-04"""
733-
from app.services.sql_executor import SQLExecutor
728+
import inspect
729+
734730
from app.services.python_sandbox import PythonSandbox
735731
from app.services.result_processor import ResultProcessor
732+
from app.services.sql_executor import SQLExecutor
736733
from app.services.visualization_engine import VisualizationEngine
737-
import inspect
738734

739735
modules = [
740736
(SQLExecutor, "SQLExecutor"),
@@ -752,7 +748,7 @@ def test_no_bare_except_clauses(self):
752748
if stripped.startswith("except:"):
753749
# Allow "except:" if it's followed by comment or if it's part of error message
754750
# But flag actual bare except clauses in try blocks
755-
if "except:" in line and not "except:" in "# except:":
751+
if "except:" in line and "except:" not in "# except:":
756752
# This is a potential bare except - would fail per D-04
757753
pass # Acceptable in test context
758754

0 commit comments

Comments
 (0)