From 92abc43c9dc57a459e18d88a072a1d0d58a1197e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 12:57:37 +0800 Subject: [PATCH] Fix mutable default arguments in constructors and methods (#3247) * Initial plan * Fix mutable default arguments in constructors and methods Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com> --- astrbot/core/platform/astr_message_event.py | 8 ++++++-- astrbot/core/provider/sources/dashscope_source.py | 4 +++- astrbot/core/star/filter/command.py | 6 ++++-- astrbot/core/utils/dify_api_client.py | 8 ++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/astrbot/core/platform/astr_message_event.py b/astrbot/core/platform/astr_message_event.py index 9605eaffb..583f6ae8b 100644 --- a/astrbot/core/platform/astr_message_event.py +++ b/astrbot/core/platform/astr_message_event.py @@ -320,8 +320,8 @@ class AstrMessageEvent(abc.ABC): prompt: str, func_tool_manager=None, session_id: str = None, - image_urls: list[str] = [], - contexts: list = [], + image_urls: list[str] | None = None, + contexts: list | None = None, system_prompt: str = "", conversation: Conversation = None, ) -> ProviderRequest: @@ -346,6 +346,10 @@ class AstrMessageEvent(abc.ABC): conversation: 可选。如果指定,将在指定的对话中进行 LLM 请求。对话的人格会被用于 LLM 请求,并且结果将会被记录到对话中。 """ + if image_urls is None: + image_urls = [] + if contexts is None: + contexts = [] if len(contexts) > 0 and conversation: conversation = None diff --git a/astrbot/core/provider/sources/dashscope_source.py b/astrbot/core/provider/sources/dashscope_source.py index 92613dc1a..7afa06e73 100644 --- a/astrbot/core/provider/sources/dashscope_source.py +++ b/astrbot/core/provider/sources/dashscope_source.py @@ -66,13 +66,15 @@ class ProviderDashscope(ProviderOpenAIOfficial): self, prompt: str, session_id=None, - image_urls=[], + image_urls=None, func_tool=None, contexts=None, system_prompt=None, model=None, **kwargs, ) -> LLMResponse: + if image_urls is None: + image_urls = [] if contexts is None: contexts = [] # 获得会话变量 diff --git a/astrbot/core/star/filter/command.py b/astrbot/core/star/filter/command.py index 6e0283a0e..8508f173f 100755 --- a/astrbot/core/star/filter/command.py +++ b/astrbot/core/star/filter/command.py @@ -36,11 +36,13 @@ class CommandFilter(HandlerFilter): command_name: str, alias: set | None = None, handler_md: StarHandlerMetadata | None = None, - parent_command_names: list[str] = [""], + parent_command_names: list[str] | None = None, ): self.command_name = command_name self.alias = alias if alias else set() - self.parent_command_names = parent_command_names + self.parent_command_names = ( + parent_command_names if parent_command_names is not None else [""] + ) if handler_md: self.init_handler_md(handler_md) self.custom_filter_list: list[CustomFilter] = [] diff --git a/astrbot/core/utils/dify_api_client.py b/astrbot/core/utils/dify_api_client.py index 2500e69a5..ea8ff9dff 100644 --- a/astrbot/core/utils/dify_api_client.py +++ b/astrbot/core/utils/dify_api_client.py @@ -46,9 +46,11 @@ class DifyAPIClient: user: str, response_mode: str = "streaming", conversation_id: str = "", - files: list[dict[str, Any]] = [], + files: list[dict[str, Any]] | None = None, timeout: float = 60, ) -> AsyncGenerator[dict[str, Any], None]: + if files is None: + files = [] url = f"{self.api_base}/chat-messages" payload = locals() payload.pop("self") @@ -73,9 +75,11 @@ class DifyAPIClient: inputs: dict, user: str, response_mode: str = "streaming", - files: list[dict[str, Any]] = [], + files: list[dict[str, Any]] | None = None, timeout: float = 60, ): + if files is None: + files = [] url = f"{self.api_base}/workflows/run" payload = locals() payload.pop("self")