fix UP042 by using StrEnum

This commit is contained in:
Bowen Liang 2024-11-06 23:55:36 +08:00
parent fec99fcc5e
commit c3f1b9978a
28 changed files with 62 additions and 62 deletions

View File

@ -1,5 +1,5 @@
from collections.abc import Sequence from collections.abc import Sequence
from enum import Enum from enum import Enum, StrEnum
from typing import Any, Optional from typing import Any, Optional
from pydantic import BaseModel, Field, field_validator from pydantic import BaseModel, Field, field_validator
@ -88,7 +88,7 @@ class PromptTemplateEntity(BaseModel):
advanced_completion_prompt_template: Optional[AdvancedCompletionPromptTemplateEntity] = None advanced_completion_prompt_template: Optional[AdvancedCompletionPromptTemplateEntity] = None
class VariableEntityType(str, Enum): class VariableEntityType(StrEnum):
TEXT_INPUT = "text-input" TEXT_INPUT = "text-input"
SELECT = "select" SELECT = "select"
PARAGRAPH = "paragraph" PARAGRAPH = "paragraph"

View File

@ -1,5 +1,5 @@
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum, StrEnum
from typing import Any, Optional from typing import Any, Optional
from pydantic import BaseModel, field_validator from pydantic import BaseModel, field_validator
@ -11,7 +11,7 @@ from core.workflow.nodes import NodeType
from core.workflow.nodes.base import BaseNodeData from core.workflow.nodes.base import BaseNodeData
class QueueEvent(str, Enum): class QueueEvent(StrEnum):
""" """
QueueEvent enum QueueEvent enum
""" """

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class FileType(str, Enum): class FileType(StrEnum):
IMAGE = "image" IMAGE = "image"
DOCUMENT = "document" DOCUMENT = "document"
AUDIO = "audio" AUDIO = "audio"
@ -16,7 +16,7 @@ class FileType(str, Enum):
raise ValueError(f"No matching enum found for value '{value}'") raise ValueError(f"No matching enum found for value '{value}'")
class FileTransferMethod(str, Enum): class FileTransferMethod(StrEnum):
REMOTE_URL = "remote_url" REMOTE_URL = "remote_url"
LOCAL_FILE = "local_file" LOCAL_FILE = "local_file"
TOOL_FILE = "tool_file" TOOL_FILE = "tool_file"
@ -29,7 +29,7 @@ class FileTransferMethod(str, Enum):
raise ValueError(f"No matching enum found for value '{value}'") raise ValueError(f"No matching enum found for value '{value}'")
class FileBelongsTo(str, Enum): class FileBelongsTo(StrEnum):
USER = "user" USER = "user"
ASSISTANT = "assistant" ASSISTANT = "assistant"
@ -41,7 +41,7 @@ class FileBelongsTo(str, Enum):
raise ValueError(f"No matching enum found for value '{value}'") raise ValueError(f"No matching enum found for value '{value}'")
class FileAttribute(str, Enum): class FileAttribute(StrEnum):
TYPE = "type" TYPE = "type"
SIZE = "size" SIZE = "size"
NAME = "name" NAME = "name"
@ -51,5 +51,5 @@ class FileAttribute(str, Enum):
EXTENSION = "extension" EXTENSION = "extension"
class ArrayFileAttribute(str, Enum): class ArrayFileAttribute(StrEnum):
LENGTH = "length" LENGTH = "length"

View File

@ -1,6 +1,6 @@
import logging import logging
from collections.abc import Mapping from collections.abc import Mapping
from enum import Enum from enum import StrEnum
from threading import Lock from threading import Lock
from typing import Any, Optional from typing import Any, Optional
@ -31,7 +31,7 @@ class CodeExecutionResponse(BaseModel):
data: Data data: Data
class CodeLanguage(str, Enum): class CodeLanguage(StrEnum):
PYTHON3 = "python3" PYTHON3 = "python3"
JINJA2 = "jinja2" JINJA2 = "jinja2"
JAVASCRIPT = "javascript" JAVASCRIPT = "javascript"

View File

@ -1,5 +1,5 @@
from abc import ABC from abc import ABC
from enum import Enum from enum import Enum, StrEnum
from typing import Optional from typing import Optional
from pydantic import BaseModel, Field, field_validator from pydantic import BaseModel, Field, field_validator
@ -93,7 +93,7 @@ class ImagePromptMessageContent(PromptMessageContent):
Model class for image prompt message content. Model class for image prompt message content.
""" """
class DETAIL(str, Enum): class DETAIL(StrEnum):
LOW = "low" LOW = "low"
HIGH = "high" HIGH = "high"

View File

@ -1,5 +1,5 @@
from decimal import Decimal from decimal import Decimal
from enum import Enum from enum import Enum, StrEnum
from typing import Any, Optional from typing import Any, Optional
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
@ -89,7 +89,7 @@ class ModelFeature(Enum):
STREAM_TOOL_CALL = "stream-tool-call" STREAM_TOOL_CALL = "stream-tool-call"
class DefaultParameterName(str, Enum): class DefaultParameterName(StrEnum):
""" """
Enum class for parameter template variable. Enum class for parameter template variable.
""" """

View File

@ -1,5 +1,5 @@
from datetime import datetime from datetime import datetime
from enum import Enum from enum import StrEnum
from typing import Any, Optional, Union from typing import Any, Optional, Union
from pydantic import BaseModel, ConfigDict, field_validator from pydantic import BaseModel, ConfigDict, field_validator
@ -122,7 +122,7 @@ trace_info_info_map = {
} }
class TraceTaskName(str, Enum): class TraceTaskName(StrEnum):
CONVERSATION_TRACE = "conversation" CONVERSATION_TRACE = "conversation"
WORKFLOW_TRACE = "workflow" WORKFLOW_TRACE = "workflow"
MESSAGE_TRACE = "message" MESSAGE_TRACE = "message"

View File

@ -1,5 +1,5 @@
from datetime import datetime from datetime import datetime
from enum import Enum from enum import StrEnum
from typing import Any, Optional, Union from typing import Any, Optional, Union
from pydantic import BaseModel, ConfigDict, Field, field_validator from pydantic import BaseModel, ConfigDict, Field, field_validator
@ -39,7 +39,7 @@ def validate_input_output(v, field_name):
return v return v
class LevelEnum(str, Enum): class LevelEnum(StrEnum):
DEBUG = "DEBUG" DEBUG = "DEBUG"
WARNING = "WARNING" WARNING = "WARNING"
ERROR = "ERROR" ERROR = "ERROR"
@ -178,7 +178,7 @@ class LangfuseSpan(BaseModel):
return validate_input_output(v, field_name) return validate_input_output(v, field_name)
class UnitEnum(str, Enum): class UnitEnum(StrEnum):
CHARACTERS = "CHARACTERS" CHARACTERS = "CHARACTERS"
TOKENS = "TOKENS" TOKENS = "TOKENS"
SECONDS = "SECONDS" SECONDS = "SECONDS"

View File

@ -1,5 +1,5 @@
from datetime import datetime from datetime import datetime
from enum import Enum from enum import StrEnum
from typing import Any, Optional, Union from typing import Any, Optional, Union
from pydantic import BaseModel, Field, field_validator from pydantic import BaseModel, Field, field_validator
@ -8,7 +8,7 @@ from pydantic_core.core_schema import ValidationInfo
from core.ops.utils import replace_text_with_content from core.ops.utils import replace_text_with_content
class LangSmithRunType(str, Enum): class LangSmithRunType(StrEnum):
tool = "tool" tool = "tool"
chain = "chain" chain = "chain"
llm = "llm" llm = "llm"

View File

@ -23,7 +23,7 @@ if TYPE_CHECKING:
from core.file.models import File from core.file.models import File
class ModelMode(str, enum.Enum): class ModelMode(enum.StrEnum):
COMPLETION = "completion" COMPLETION = "completion"
CHAT = "chat" CHAT = "chat"

View File

@ -1,5 +1,5 @@
from enum import Enum from enum import StrEnum
class KeyWordType(str, Enum): class KeyWordType(StrEnum):
JIEBA = "jieba" JIEBA = "jieba"

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class VectorType(str, Enum): class VectorType(StrEnum):
ANALYTICDB = "analyticdb" ANALYTICDB = "analyticdb"
CHROMA = "chroma" CHROMA = "chroma"
MILVUS = "milvus" MILVUS = "milvus"

View File

@ -1,6 +1,6 @@
from enum import Enum from enum import StrEnum
class RerankMode(str, Enum): class RerankMode(StrEnum):
RERANKING_MODEL = "reranking_model" RERANKING_MODEL = "reranking_model"
WEIGHTED_SCORE = "weighted_score" WEIGHTED_SCORE = "weighted_score"

View File

@ -1,4 +1,4 @@
from enum import Enum from enum import Enum, StrEnum
from typing import Any, Optional, Union, cast from typing import Any, Optional, Union, cast
from pydantic import BaseModel, Field, field_validator from pydantic import BaseModel, Field, field_validator
@ -137,7 +137,7 @@ class ToolParameterOption(BaseModel):
class ToolParameter(BaseModel): class ToolParameter(BaseModel):
class ToolParameterType(str, Enum): class ToolParameterType(StrEnum):
STRING = "string" STRING = "string"
NUMBER = "number" NUMBER = "number"
BOOLEAN = "boolean" BOOLEAN = "boolean"

View File

@ -1,7 +1,7 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections.abc import Mapping from collections.abc import Mapping
from copy import deepcopy from copy import deepcopy
from enum import Enum from enum import Enum, StrEnum
from typing import TYPE_CHECKING, Any, Optional, Union from typing import TYPE_CHECKING, Any, Optional, Union
from pydantic import BaseModel, ConfigDict, field_validator from pydantic import BaseModel, ConfigDict, field_validator
@ -62,7 +62,7 @@ class Tool(BaseModel, ABC):
def __init__(self, **data: Any): def __init__(self, **data: Any):
super().__init__(**data) super().__init__(**data)
class VariableKey(str, Enum): class VariableKey(StrEnum):
IMAGE = "image" IMAGE = "image"
DOCUMENT = "document" DOCUMENT = "document"
VIDEO = "video" VIDEO = "video"

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class SegmentType(str, Enum): class SegmentType(StrEnum):
NONE = "none" NONE = "none"
NUMBER = "number" NUMBER = "number"
STRING = "string" STRING = "string"

View File

@ -1,5 +1,5 @@
from collections.abc import Mapping from collections.abc import Mapping
from enum import Enum from enum import StrEnum
from typing import Any, Optional from typing import Any, Optional
from pydantic import BaseModel from pydantic import BaseModel
@ -8,7 +8,7 @@ from core.model_runtime.entities.llm_entities import LLMUsage
from models.workflow import WorkflowNodeExecutionStatus from models.workflow import WorkflowNodeExecutionStatus
class NodeRunMetadataKey(str, Enum): class NodeRunMetadataKey(StrEnum):
""" """
Node Run Metadata Key. Node Run Metadata Key.
""" """

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class SystemVariableKey(str, Enum): class SystemVariableKey(StrEnum):
""" """
System Variables. System Variables.
""" """

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class NodeType(str, Enum): class NodeType(StrEnum):
START = "start" START = "start"
END = "end" END = "end"
ANSWER = "answer" ANSWER = "answer"

View File

@ -1,4 +1,4 @@
from enum import Enum from enum import StrEnum
from typing import Any, Optional from typing import Any, Optional
from pydantic import Field from pydantic import Field
@ -6,7 +6,7 @@ from pydantic import Field
from core.workflow.nodes.base import BaseIterationNodeData, BaseIterationState, BaseNodeData from core.workflow.nodes.base import BaseIterationNodeData, BaseIterationState, BaseNodeData
class ErrorHandleMode(str, Enum): class ErrorHandleMode(StrEnum):
TERMINATED = "terminated" TERMINATED = "terminated"
CONTINUE_ON_ERROR = "continue-on-error" CONTINUE_ON_ERROR = "continue-on-error"
REMOVE_ABNORMAL_OUTPUT = "remove-abnormal-output" REMOVE_ABNORMAL_OUTPUT = "remove-abnormal-output"

View File

@ -1,11 +1,11 @@
from collections.abc import Sequence from collections.abc import Sequence
from enum import Enum from enum import StrEnum
from typing import Optional from typing import Optional
from core.workflow.nodes.base import BaseNodeData from core.workflow.nodes.base import BaseNodeData
class WriteMode(str, Enum): class WriteMode(StrEnum):
OVER_WRITE = "over-write" OVER_WRITE = "over-write"
APPEND = "append" APPEND = "append"
CLEAR = "clear" CLEAR = "clear"

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class StorageType(str, Enum): class StorageType(StrEnum):
ALIYUN_OSS = "aliyun-oss" ALIYUN_OSS = "aliyun-oss"
AZURE_BLOB = "azure-blob" AZURE_BLOB = "azure-blob"
BAIDU_OBS = "baidu-obs" BAIDU_OBS = "baidu-obs"

View File

@ -8,7 +8,7 @@ from extensions.ext_database import db
from .types import StringUUID from .types import StringUUID
class AccountStatus(str, enum.Enum): class AccountStatus(enum.StrEnum):
PENDING = "pending" PENDING = "pending"
UNINITIALIZED = "uninitialized" UNINITIALIZED = "uninitialized"
ACTIVE = "active" ACTIVE = "active"
@ -121,12 +121,12 @@ class Account(UserMixin, db.Model):
return self._current_tenant.current_role == TenantAccountRole.DATASET_OPERATOR return self._current_tenant.current_role == TenantAccountRole.DATASET_OPERATOR
class TenantStatus(str, enum.Enum): class TenantStatus(enum.StrEnum):
NORMAL = "normal" NORMAL = "normal"
ARCHIVE = "archive" ARCHIVE = "archive"
class TenantAccountRole(str, enum.Enum): class TenantAccountRole(enum.StrEnum):
OWNER = "owner" OWNER = "owner"
ADMIN = "admin" ADMIN = "admin"
EDITOR = "editor" EDITOR = "editor"

View File

@ -23,7 +23,7 @@ from .model import App, Tag, TagBinding, UploadFile
from .types import StringUUID from .types import StringUUID
class DatasetPermissionEnum(str, enum.Enum): class DatasetPermissionEnum(enum.StrEnum):
ONLY_ME = "only_me" ONLY_ME = "only_me"
ALL_TEAM = "all_team_members" ALL_TEAM = "all_team_members"
PARTIAL_TEAM = "partial_members" PARTIAL_TEAM = "partial_members"

View File

@ -1,16 +1,16 @@
from enum import Enum from enum import StrEnum
class CreatedByRole(str, Enum): class CreatedByRole(StrEnum):
ACCOUNT = "account" ACCOUNT = "account"
END_USER = "end_user" END_USER = "end_user"
class UserFrom(str, Enum): class UserFrom(StrEnum):
ACCOUNT = "account" ACCOUNT = "account"
END_USER = "end-user" END_USER = "end-user"
class WorkflowRunTriggeredFrom(str, Enum): class WorkflowRunTriggeredFrom(StrEnum):
DEBUGGING = "debugging" DEBUGGING = "debugging"
APP_RUN = "app-run" APP_RUN = "app-run"

View File

@ -3,7 +3,7 @@ import re
import uuid import uuid
from collections.abc import Mapping from collections.abc import Mapping
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum, StrEnum
from typing import Any, Literal, Optional from typing import Any, Literal, Optional
import sqlalchemy as sa import sqlalchemy as sa
@ -32,7 +32,7 @@ class DifySetup(db.Model):
setup_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)")) setup_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)"))
class AppMode(str, Enum): class AppMode(StrEnum):
COMPLETION = "completion" COMPLETION = "completion"
WORKFLOW = "workflow" WORKFLOW = "workflow"
CHAT = "chat" CHAT = "chat"

View File

@ -1,6 +1,6 @@
from enum import Enum from enum import StrEnum
class AuthType(str, Enum): class AuthType(StrEnum):
FIRECRAWL = "firecrawl" FIRECRAWL = "firecrawl"
JINA = "jinareader" JINA = "jinareader"

View File

@ -1,7 +1,7 @@
from enum import Enum from enum import StrEnum
class RecommendAppType(str, Enum): class RecommendAppType(StrEnum):
REMOTE = "remote" REMOTE = "remote"
BUILDIN = "builtin" BUILDIN = "builtin"
DATABASE = "db" DATABASE = "db"