remove bare list, dict, Sequence, None, Any (#25058)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
Asuka Minato
2025-09-06 04:32:23 +09:00
committed by GitHub
parent 2b0695bdde
commit a78339a040
306 changed files with 787 additions and 817 deletions

View File

@@ -225,7 +225,7 @@ class Tenant(Base):
)
@property
def custom_config_dict(self) -> dict:
def custom_config_dict(self):
return json.loads(self.custom_config) if self.custom_config else {}
@custom_config_dict.setter

View File

@@ -162,7 +162,7 @@ class App(Base):
return str(self.mode)
@property
def deleted_tools(self) -> list:
def deleted_tools(self):
from core.tools.tool_manager import ToolManager
from services.plugin.plugin_service import PluginService
@@ -339,15 +339,15 @@ class AppModelConfig(Base):
return app
@property
def model_dict(self) -> dict:
def model_dict(self):
return json.loads(self.model) if self.model else {}
@property
def suggested_questions_list(self) -> list:
def suggested_questions_list(self):
return json.loads(self.suggested_questions) if self.suggested_questions else []
@property
def suggested_questions_after_answer_dict(self) -> dict:
def suggested_questions_after_answer_dict(self):
return (
json.loads(self.suggested_questions_after_answer)
if self.suggested_questions_after_answer
@@ -355,19 +355,19 @@ class AppModelConfig(Base):
)
@property
def speech_to_text_dict(self) -> dict:
def speech_to_text_dict(self):
return json.loads(self.speech_to_text) if self.speech_to_text else {"enabled": False}
@property
def text_to_speech_dict(self) -> dict:
def text_to_speech_dict(self):
return json.loads(self.text_to_speech) if self.text_to_speech else {"enabled": False}
@property
def retriever_resource_dict(self) -> dict:
def retriever_resource_dict(self):
return json.loads(self.retriever_resource) if self.retriever_resource else {"enabled": True}
@property
def annotation_reply_dict(self) -> dict:
def annotation_reply_dict(self):
annotation_setting = (
db.session.query(AppAnnotationSetting).where(AppAnnotationSetting.app_id == self.app_id).first()
)
@@ -390,11 +390,11 @@ class AppModelConfig(Base):
return {"enabled": False}
@property
def more_like_this_dict(self) -> dict:
def more_like_this_dict(self):
return json.loads(self.more_like_this) if self.more_like_this else {"enabled": False}
@property
def sensitive_word_avoidance_dict(self) -> dict:
def sensitive_word_avoidance_dict(self):
return (
json.loads(self.sensitive_word_avoidance)
if self.sensitive_word_avoidance
@@ -410,7 +410,7 @@ class AppModelConfig(Base):
return json.loads(self.user_input_form) if self.user_input_form else []
@property
def agent_mode_dict(self) -> dict:
def agent_mode_dict(self):
return (
json.loads(self.agent_mode)
if self.agent_mode
@@ -418,15 +418,15 @@ class AppModelConfig(Base):
)
@property
def chat_prompt_config_dict(self) -> dict:
def chat_prompt_config_dict(self):
return json.loads(self.chat_prompt_config) if self.chat_prompt_config else {}
@property
def completion_prompt_config_dict(self) -> dict:
def completion_prompt_config_dict(self):
return json.loads(self.completion_prompt_config) if self.completion_prompt_config else {}
@property
def dataset_configs_dict(self) -> dict:
def dataset_configs_dict(self):
if self.dataset_configs:
dataset_configs: dict = json.loads(self.dataset_configs)
if "retrieval_model" not in dataset_configs:
@@ -438,7 +438,7 @@ class AppModelConfig(Base):
}
@property
def file_upload_dict(self) -> dict:
def file_upload_dict(self):
return (
json.loads(self.file_upload)
if self.file_upload
@@ -452,7 +452,7 @@ class AppModelConfig(Base):
}
)
def to_dict(self) -> dict:
def to_dict(self):
return {
"opening_statement": self.opening_statement,
"suggested_questions": self.suggested_questions_list,
@@ -1087,7 +1087,7 @@ class Message(Base):
return self.override_model_configs is not None
@property
def message_metadata_dict(self) -> dict:
def message_metadata_dict(self):
return json.loads(self.message_metadata) if self.message_metadata else {}
@property
@@ -1176,7 +1176,7 @@ class Message(Base):
return None
def to_dict(self) -> dict:
def to_dict(self):
return {
"id": self.id,
"app_id": self.app_id,
@@ -1689,7 +1689,7 @@ class MessageAgentThought(Base):
created_at = mapped_column(sa.DateTime, nullable=False, server_default=db.func.current_timestamp())
@property
def files(self) -> list:
def files(self):
if self.message_files:
return cast(list[Any], json.loads(self.message_files))
else:
@@ -1700,7 +1700,7 @@ class MessageAgentThought(Base):
return self.tool.split(";") if self.tool else []
@property
def tool_labels(self) -> dict:
def tool_labels(self):
try:
if self.tool_labels_str:
return cast(dict, json.loads(self.tool_labels_str))
@@ -1710,7 +1710,7 @@ class MessageAgentThought(Base):
return {}
@property
def tool_meta(self) -> dict:
def tool_meta(self):
try:
if self.tool_meta_str:
return cast(dict, json.loads(self.tool_meta_str))
@@ -1720,7 +1720,7 @@ class MessageAgentThought(Base):
return {}
@property
def tool_inputs_dict(self) -> dict:
def tool_inputs_dict(self):
tools = self.tools
try:
if self.tool_input:

View File

@@ -1,6 +1,6 @@
import json
from datetime import datetime
from typing import Any, Optional, cast
from typing import Optional, cast
from urllib.parse import urlparse
import sqlalchemy as sa
@@ -54,7 +54,7 @@ class ToolOAuthTenantClient(Base):
encrypted_oauth_params: Mapped[str] = mapped_column(sa.Text, nullable=False)
@property
def oauth_params(self) -> dict:
def oauth_params(self):
return cast(dict, json.loads(self.encrypted_oauth_params or "{}"))
@@ -96,7 +96,7 @@ class BuiltinToolProvider(Base):
expires_at: Mapped[int] = mapped_column(sa.BigInteger, nullable=False, server_default=sa.text("-1"))
@property
def credentials(self) -> dict:
def credentials(self):
return cast(dict, json.loads(self.encrypted_credentials))
@@ -146,7 +146,7 @@ class ApiToolProvider(Base):
return [ApiToolBundle(**tool) for tool in json.loads(self.tools_str)]
@property
def credentials(self) -> dict:
def credentials(self):
return dict(json.loads(self.credentials_str))
@property
@@ -289,7 +289,7 @@ class MCPToolProvider(Base):
return db.session.query(Tenant).where(Tenant.id == self.tenant_id).first()
@property
def credentials(self) -> dict:
def credentials(self):
try:
return cast(dict, json.loads(self.encrypted_credentials)) or {}
except Exception:
@@ -327,7 +327,7 @@ class MCPToolProvider(Base):
return mask_url(self.decrypted_server_url)
@property
def decrypted_credentials(self) -> dict:
def decrypted_credentials(self):
from core.helper.provider_cache import NoOpProviderCredentialCache
from core.tools.mcp_tool.provider import MCPToolProviderController
from core.tools.utils.encryption import create_provider_encrypter
@@ -408,7 +408,7 @@ class ToolConversationVariables(Base):
updated_at = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())
@property
def variables(self) -> Any:
def variables(self):
return json.loads(self.variables_str)

View File

@@ -282,14 +282,14 @@ class Workflow(Base):
return self._features
@features.setter
def features(self, value: str) -> None:
def features(self, value: str):
self._features = value
@property
def features_dict(self) -> dict[str, Any]:
return json.loads(self.features) if self.features else {}
def user_input_form(self, to_old_structure: bool = False) -> list:
def user_input_form(self, to_old_structure: bool = False):
# get start node from graph
if not self.graph:
return []
@@ -439,7 +439,7 @@ class Workflow(Base):
return results
@conversation_variables.setter
def conversation_variables(self, value: Sequence[Variable]) -> None:
def conversation_variables(self, value: Sequence[Variable]):
self._conversation_variables = json.dumps(
{var.name: var.model_dump() for var in value},
ensure_ascii=False,
@@ -892,7 +892,7 @@ class ConversationVariable(Base):
DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp()
)
def __init__(self, *, id: str, app_id: str, conversation_id: str, data: str) -> None:
def __init__(self, *, id: str, app_id: str, conversation_id: str, data: str):
self.id = id
self.app_id = app_id
self.conversation_id = conversation_id
@@ -1073,7 +1073,7 @@ class WorkflowDraftVariable(Base):
return self.build_segment_with_type(self.value_type, value)
@staticmethod
def rebuild_file_types(value: Any) -> Any:
def rebuild_file_types(value: Any):
# NOTE(QuantumGhost): Temporary workaround for structured data handling.
# By this point, `output` has been converted to dict by
# `WorkflowEntry.handle_special_values`, so we need to