Skip to content

Commit

Permalink
fix: mypy version
Browse files Browse the repository at this point in the history
Signed-off-by: yihong0618 <[email protected]>
  • Loading branch information
yihong0618 committed Dec 23, 2024
1 parent 767df75 commit 93cc22d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion api/controllers/console/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def get(self, provider: str):
token = oauth_provider.get_access_token(code)
user_info = oauth_provider.get_user_info(token)
except requests.exceptions.RequestException as e:
logging.exception(f"An error occurred during the OAuth process with {provider}: {e.response.text}")
error_text = e.response.text if e.response else str(e)
logging.exception(f"An error occurred during the OAuth process with {provider}: {error_text}")
return {"error": "OAuth process failed"}, 400

if invite_token and RegisterService.is_valid_invite_token(invite_token):
Expand Down
6 changes: 3 additions & 3 deletions api/core/app/apps/advanced_chat/generate_task_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ def _process_stream_response(

workflow_node_execution = self._handle_node_execution_start(workflow_run=workflow_run, event=event)

response = self._workflow_node_start_to_stream_response(
response_start = self._workflow_node_start_to_stream_response(
event=event,
task_id=self._application_generate_entity.task_id,
workflow_node_execution=workflow_node_execution,
)

if response:
yield response
if response_start:
yield response_start
elif isinstance(event, QueueNodeSucceededEvent):
workflow_node_execution = self._handle_workflow_node_execution_success(event)

Expand Down
2 changes: 1 addition & 1 deletion api/core/app/apps/workflow_app_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _handle_event(self, workflow_entry: WorkflowEntry, event: GraphEngineEvent)
inputs=inputs,
process_data=process_data,
outputs=outputs,
execution_metadata=execution_metadata,
execution_metadata=dict(execution_metadata) if execution_metadata else None,
in_iteration_id=event.in_iteration_id,
)
)
Expand Down
2 changes: 1 addition & 1 deletion api/core/workflow/graph_engine/graph_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def _run_node(
parallel_start_node_id=parallel_start_node_id,
parent_parallel_id=parent_parallel_id,
parent_parallel_start_node_id=parent_parallel_start_node_id,
error=run_result.error,
error=run_result.error or "Unknown error",
retry_index=retries,
start_at=retry_start_at,
)
Expand Down
4 changes: 2 additions & 2 deletions api/core/workflow/nodes/answer/base_stream_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def _remove_unreachable_nodes(self, event: NodeRunSucceededEvent | NodeRunExcept
return

if run_result.edge_source_handle:
reachable_node_ids = []
unreachable_first_node_ids = []
reachable_node_ids: list[str] = []
unreachable_first_node_ids: list[str] = []
if finished_node_id not in self.graph.edge_mapping:
logger.warning(f"node {finished_node_id} has no edge mapping")
return
Expand Down
2 changes: 1 addition & 1 deletion api/core/workflow/nodes/event/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class RunRetryEvent(BaseModel):
class SingleStepRetryEvent(NodeRunResult):
"""Single step retry event"""

status: str = WorkflowNodeExecutionStatus.RETRY.value
status: WorkflowNodeExecutionStatus = WorkflowNodeExecutionStatus.RETRY

elapsed_time: float = Field(..., description="elapsed time")
6 changes: 3 additions & 3 deletions api/core/workflow/nodes/http_request/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ def to_log(self):
elif self.node_data.body.type == "raw-text":
if len(self.node_data.body.data) != 1:
raise RequestBodyError("raw-text body type should have exactly one item")
body = self.node_data.body.data[0].value
if body:
raw += f"Content-Length: {len(body)}\r\n"
body_string = self.node_data.body.data[0].value
if body_string:
raw += f"Content-Length: {len(body_string)}\r\n"
raw += "\r\n" # Empty line between headers and body
raw += body_string

Expand Down
4 changes: 2 additions & 2 deletions api/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Mapping
from datetime import datetime
from enum import Enum, StrEnum
from typing import TYPE_CHECKING, Any, Literal, Optional
from typing import TYPE_CHECKING, Any, Literal, Optional, cast

import sqlalchemy as sa
from flask import request
Expand Down Expand Up @@ -1545,7 +1545,7 @@ class MessageAgentThought(db.Model): # type: ignore[name-defined]
@property
def files(self) -> list:
if self.message_files:
return cast(list, json.loads(self.message_files))
return cast(list[Any], json.loads(self.message_files))
else:
return []

Expand Down
1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ optional = true
[tool.poetry.group.dev.dependencies]
coverage = "~7.2.4"
faker = "~32.1.0"
mypy = "~1.13.0"
pytest = "~8.3.2"
pytest-benchmark = "~4.0.0"
pytest-env = "~1.1.3"
Expand Down
4 changes: 2 additions & 2 deletions api/services/workflow_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from collections.abc import Sequence
from datetime import UTC, datetime
from typing import Optional, cast
from typing import Any, Optional, cast

from core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfigManager
from core.app.apps.workflow.app_config_manager import WorkflowAppConfigManager
Expand Down Expand Up @@ -242,7 +242,7 @@ def run_draft_workflow_node(
raise ValueError("Node run failed with no run result")
# single step debug mode error handling return
if node_run_result.status == WorkflowNodeExecutionStatus.FAILED and node_instance.should_continue_on_error:
node_error_args = {
node_error_args: dict[str, Any] = {
"status": WorkflowNodeExecutionStatus.EXCEPTION,
"error": node_run_result.error,
"inputs": node_run_result.inputs,
Expand Down

0 comments on commit 93cc22d

Please sign in to comment.