refactor: replace bare dict with dict[str, Any] in entities, workflow nodes, and tasks (#35109)

This commit is contained in:
wdeveloper16 2026-04-14 05:02:39 +02:00 committed by GitHub
parent 4ee1bd5f32
commit ed83f5369e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 34 additions and 26 deletions

View File

@ -14,7 +14,7 @@ class DatasourceApiEntity(BaseModel):
description: I18nObject
parameters: list[DatasourceParameter] | None = None
labels: list[str] = Field(default_factory=list)
output_schema: dict | None = None
output_schema: dict[str, Any] | None = None
ToolProviderTypeApiLiteral = Literal["builtin", "api", "workflow"] | None
@ -30,7 +30,7 @@ class DatasourceProviderApiEntityDict(TypedDict):
icon: str | dict
label: I18nObjectDict
type: str
team_credentials: dict | None
team_credentials: dict[str, Any] | None
is_team_authorization: bool
allow_delete: bool
datasources: list[Any]
@ -45,8 +45,8 @@ class DatasourceProviderApiEntity(BaseModel):
icon: str | dict
label: I18nObject # label
type: str
masked_credentials: dict | None = None
original_credentials: dict | None = None
masked_credentials: dict[str, Any] | None = None
original_credentials: dict[str, Any] | None = None
is_team_authorization: bool = False
allow_delete: bool = True
plugin_id: str | None = Field(default="", description="The plugin id of the datasource")

View File

@ -43,15 +43,20 @@ class IndexProcessorProtocol(Protocol):
original_document_id: str,
chunks: Mapping[str, Any],
batch: Any,
summary_index_setting: dict | None = None,
summary_index_setting: dict[str, Any] | None = None,
) -> IndexingResultDict: ...
def get_preview_output(
self, chunks: Any, dataset_id: str, document_id: str, chunk_structure: str, summary_index_setting: dict | None
self,
chunks: Any,
dataset_id: str,
document_id: str,
chunk_structure: str,
summary_index_setting: dict[str, Any] | None,
) -> Preview: ...
class SummaryIndexServiceProtocol(Protocol):
def generate_and_vectorize_summary(
self, dataset_id: str, document_id: str, is_preview: bool, summary_index_setting: dict | None = None
self, dataset_id: str, document_id: str, is_preview: bool, summary_index_setting: dict[str, Any] | None = None
) -> None: ...

View File

@ -1,4 +1,4 @@
from typing import Literal, Union
from typing import Any, Literal, Union
from graphon.entities.base_node_data import BaseNodeData
from graphon.enums import NodeType
@ -16,7 +16,7 @@ class TriggerScheduleNodeData(BaseNodeData):
mode: str = Field(default="visual", description="Schedule mode: visual or cron")
frequency: str | None = Field(default=None, description="Frequency for visual mode: hourly, daily, weekly, monthly")
cron_expression: str | None = Field(default=None, description="Cron expression for cron mode")
visual_config: dict | None = Field(default=None, description="Visual configuration details")
visual_config: dict[str, Any] | None = Field(default=None, description="Visual configuration details")
timezone: str = Field(default="UTC", description="Timezone for schedule execution")

View File

@ -75,7 +75,7 @@ class TriggerWebhookNode(Node[WebhookData]):
outputs=outputs,
)
def generate_file_var(self, param_name: str, file: dict):
def generate_file_var(self, param_name: str, file: dict[str, Any]):
file_id = resolve_file_record_id(file.get("reference") or file.get("related_id"))
transfer_method_value = file.get("transfer_method")
if transfer_method_value:
@ -147,7 +147,7 @@ class TriggerWebhookNode(Node[WebhookData]):
outputs[param_name] = str(webhook_data.get("body", {}).get("raw", ""))
continue
elif self.node_data.content_type == ContentType.BINARY:
raw_data: dict = webhook_data.get("body", {}).get("raw", {})
raw_data: dict[str, Any] = webhook_data.get("body", {}).get("raw", {})
file_var = self.generate_file_var(param_name, raw_data)
if file_var:
outputs[param_name] = file_var

View File

@ -65,7 +65,7 @@ class FileMetadata:
return data
@classmethod
def from_dict(cls, data: dict) -> FileMetadata:
def from_dict(cls, data: dict[str, Any]) -> FileMetadata:
"""Create instance from dictionary"""
data = data.copy()
data["created_at"] = datetime.fromisoformat(data["created_at"])
@ -459,7 +459,7 @@ class FileLifecycleManager:
newest_file=None,
)
def _create_version_backup(self, filename: str, metadata: dict):
def _create_version_backup(self, filename: str, metadata: dict[str, Any]):
"""Create version backup"""
try:
# Read current file content
@ -487,7 +487,7 @@ class FileLifecycleManager:
logger.warning("Failed to load metadata: %s", e)
return {}
def _save_metadata(self, metadata_dict: dict):
def _save_metadata(self, metadata_dict: dict[str, Any]):
"""Save metadata file"""
try:
metadata_content = json.dumps(metadata_dict, indent=2, ensure_ascii=False)

View File

@ -1,4 +1,4 @@
from typing import Literal, Union
from typing import Any, Literal, Union
from pydantic import BaseModel
@ -22,5 +22,5 @@ class ProcessStatusSetting(BaseModel):
class ExternalKnowledgeApiSetting(BaseModel):
url: str
request_method: str
headers: dict | None = None
params: dict | None = None
headers: dict[str, Any] | None = None
params: dict[str, Any] | None = None

View File

@ -1,4 +1,4 @@
from typing import Literal
from typing import Any, Literal
from pydantic import BaseModel, field_validator
@ -97,7 +97,7 @@ class KnowledgeConfig(BaseModel):
data_source: DataSource | None = None
process_rule: ProcessRule | None = None
retrieval_model: RetrievalModel | None = None
summary_index_setting: dict | None = None
summary_index_setting: dict[str, Any] | None = None
doc_form: str = "text_model"
doc_language: str = "English"
embedding_model: str | None = None

View File

@ -1,4 +1,4 @@
from typing import Literal
from typing import Any, Literal
from pydantic import BaseModel, field_validator
@ -73,7 +73,7 @@ class KnowledgeConfiguration(BaseModel):
keyword_number: int | None = 10
retrieval_model: RetrievalSetting
# add summary index setting
summary_index_setting: dict | None = None
summary_index_setting: dict[str, Any] | None = None
@field_validator("embedding_model_provider", mode="before")
@classmethod

View File

@ -3,6 +3,7 @@ import tempfile
import time
import uuid
from pathlib import Path
from typing import Any
import click
import pandas as pd
@ -51,8 +52,8 @@ def batch_create_segment_to_index_task(
# Initialize variables with default values
upload_file_key: str | None = None
dataset_config: dict | None = None
document_config: dict | None = None
dataset_config: dict[str, Any] | None = None
document_config: dict[str, Any] | None = None
with session_factory.create_session() as session:
try:

View File

@ -679,7 +679,7 @@ def _delete_workflow_trigger_logs(tenant_id: str, app_id: str):
)
def _delete_records(query_sql: str, params: dict, delete_func: Callable, name: str) -> None:
def _delete_records(query_sql: str, params: dict[str, Any], delete_func: Callable, name: str) -> None:
while True:
with session_factory.create_session() as session:
rs = session.execute(sa.text(query_sql), params)

View File

@ -7,6 +7,7 @@ improving performance by offloading storage operations to background workers.
import json
import logging
from typing import Any
from celery import shared_task
from graphon.entities import WorkflowExecution
@ -23,7 +24,7 @@ logger = logging.getLogger(__name__)
@shared_task(queue="workflow_storage", bind=True, max_retries=3, default_retry_delay=60)
def save_workflow_execution_task(
self,
execution_data: dict,
execution_data: dict[str, Any],
tenant_id: str,
app_id: str,
triggered_from: str,

View File

@ -7,6 +7,7 @@ improving performance by offloading storage operations to background workers.
import json
import logging
from typing import Any
from celery import shared_task
from graphon.entities.workflow_node_execution import (
@ -25,7 +26,7 @@ logger = logging.getLogger(__name__)
@shared_task(queue="workflow_storage", bind=True, max_retries=3, default_retry_delay=60)
def save_workflow_node_execution_task(
self,
execution_data: dict,
execution_data: dict[str, Any],
tenant_id: str,
app_id: str,
triggered_from: str,