From d6fd5f170ab250cad9e3786912fdbd05be850d64 Mon Sep 17 00:00:00 2001 From: BalconyJH <73932916+BalconyJH@users.noreply.github.com> Date: Mon, 27 Jan 2025 03:40:50 +0800 Subject: [PATCH] :rotating_light: Make pyright happy (#1840) --- zhenxun/builtin_plugins/shop/_data_source.py | 5 +++-- .../web_ui/api/tabs/manage/model.py | 6 ++++-- zhenxun/configs/config.py | 5 +++-- zhenxun/configs/utils/__init__.py | 14 +++++++------- zhenxun/utils/_build_mat.py | 9 +++++---- zhenxun/utils/decorator/shop.py | 7 ++++--- zhenxun/utils/github_utils/models.py | 3 ++- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/zhenxun/builtin_plugins/shop/_data_source.py b/zhenxun/builtin_plugins/shop/_data_source.py index 1e4af3912..eb2915bda 100644 --- a/zhenxun/builtin_plugins/shop/_data_source.py +++ b/zhenxun/builtin_plugins/shop/_data_source.py @@ -1,5 +1,6 @@ import asyncio from collections.abc import Callable +from dataclasses import field from datetime import datetime, timedelta import inspect import time @@ -32,9 +33,9 @@ class Goods(BaseModel): name: str """商品名称""" - before_handle: list[Callable] = [] + before_handle: list[Callable] = field(default_factory=list) """使用前函数""" - after_handle: list[Callable] = [] + after_handle: list[Callable] = field(default_factory=list) """使用后函数""" func: Callable | None = None """使用函数""" diff --git a/zhenxun/builtin_plugins/web_ui/api/tabs/manage/model.py b/zhenxun/builtin_plugins/web_ui/api/tabs/manage/model.py index 7afe9dd22..cdb7ed75f 100644 --- a/zhenxun/builtin_plugins/web_ui/api/tabs/manage/model.py +++ b/zhenxun/builtin_plugins/web_ui/api/tabs/manage/model.py @@ -1,3 +1,5 @@ +from dataclasses import field + from nonebot.compat import model_dump from pydantic import BaseModel @@ -172,9 +174,9 @@ class ReqResult(BaseModel): 好友/群组请求列表 """ - friend: list[FriendRequestResult] = [] + friend: list[FriendRequestResult] = field(default_factory=list) """好友请求列表""" - group: list[GroupRequestResult] = [] + group: list[GroupRequestResult] = field(default_factory=list) """群组请求列表""" diff --git a/zhenxun/configs/config.py b/zhenxun/configs/config.py index d0bc69827..9dc12ab6b 100644 --- a/zhenxun/configs/config.py +++ b/zhenxun/configs/config.py @@ -1,3 +1,4 @@ +from dataclasses import field from pathlib import Path import nonebot @@ -13,9 +14,9 @@ class BotSetting(BaseModel): """系统代理""" db_url: str = "" """数据库链接""" - platform_superusers: dict[str, list[str]] = {} + platform_superusers: dict[str, list[str]] = field(default_factory=dict) """平台超级用户""" - qbot_id_data: dict[str, str] = {} + qbot_id_data: dict[str, str] = field(default_factory=dict) """官bot id:账号id""" def get_qbot_uid(self, qbot_id: str) -> str | None: diff --git a/zhenxun/configs/utils/__init__.py b/zhenxun/configs/utils/__init__.py index 54a5badb2..8477d6bbe 100644 --- a/zhenxun/configs/utils/__init__.py +++ b/zhenxun/configs/utils/__init__.py @@ -1,6 +1,6 @@ -from collections import defaultdict from collections.abc import Callable import copy +from dataclasses import field from datetime import datetime from pathlib import Path from typing import Any, Literal @@ -38,11 +38,11 @@ class Command(BaseModel): command: str """命令名称""" - params: list[str] = [] + params: list[str] = field(default_factory=list) """参数""" description: str = "" """描述""" - examples: list[Example] = [] + examples: list[Example] = field(default_factory=list) """示例列表""" @@ -96,7 +96,7 @@ class ConfigGroup(BaseModel): """模块名""" name: str | None = None """插件名""" - configs: dict[str, ConfigModel] = defaultdict() + configs: dict[str, ConfigModel] = field(default_factory=dict) """配置项列表""" def get(self, c: str, default: Any = None) -> Any: @@ -209,7 +209,7 @@ class Task(BaseBlock): """运行函数""" check: Callable | None = None """检查函数""" - check_args: list = [] + check_args: list = field(default_factory=list) """检查函数参数""" @@ -234,7 +234,7 @@ class PluginExtraData(BaseModel): """插件基本配置""" limits: list[BaseBlock | PluginCdBlock | PluginCountBlock] | None = None """插件限制""" - commands: list[Command] = [] + commands: list[Command] = field(default_factory=list) """命令列表,用于说明帮助""" ignore_prompt: bool = False """是否忽略阻断提示""" @@ -242,7 +242,7 @@ class PluginExtraData(BaseModel): """技能被动""" superuser_help: str | None = None """超级用户帮助""" - aliases: set[str] = set() + aliases: set[str] = field(default_factory=set) """额外名称""" sql_list: list[str] | None = None """常用sql""" diff --git a/zhenxun/utils/_build_mat.py b/zhenxun/utils/_build_mat.py index e41f2cda8..ce8193bae 100644 --- a/zhenxun/utils/_build_mat.py +++ b/zhenxun/utils/_build_mat.py @@ -1,3 +1,4 @@ +from dataclasses import field from io import BytesIO from pathlib import Path import random @@ -20,15 +21,15 @@ class MatType(StrEnum): class BuildMatData(BaseModel): mat_type: MatType """类型""" - data: list[int | float] = [] + data: list[int | float] = field(default_factory=list) """数据""" x_name: str | None = None """X轴坐标名称""" y_name: str | None = None """Y轴坐标名称""" - x_index: list[str] = [] + x_index: list[str] = field(default_factory=list) """显示轴坐标值""" - y_index: list[int | float] = [] + y_index: list[int | float] = field(default_factory=list) """数据轴坐标值""" space: tuple[int, int] = (20, 20) """坐标值间隔(X, Y)""" @@ -48,7 +49,7 @@ class BuildMatData(BaseModel): """背景颜色""" background: Path | bytes | None = None """背景图片""" - bar_color: list[str] = ["*"] + bar_color: list[str] = field(default_factory=lambda: ["*"]) """柱状图柱子颜色, 多个时随机, 使用 * 时七色随机""" padding: tuple[int, int] = (50, 50) """图表上下左右边距""" diff --git a/zhenxun/utils/decorator/shop.py b/zhenxun/utils/decorator/shop.py index f84225b5d..a04908722 100644 --- a/zhenxun/utils/decorator/shop.py +++ b/zhenxun/utils/decorator/shop.py @@ -1,4 +1,5 @@ from collections.abc import Callable +from dataclasses import field from nonebot.adapters.onebot.v11 import Message, MessageSegment from nonebot.plugin import require @@ -8,8 +9,8 @@ class Goods(BaseModel): - before_handle: list[Callable] = [] - after_handle: list[Callable] = [] + before_handle: list[Callable] = field(default_factory=list) + after_handle: list[Callable] = field(default_factory=list) price: int des: str = "" discount: float @@ -19,7 +20,7 @@ class Goods(BaseModel): is_passive: bool partition: str | None func: Callable - kwargs: dict[str, str] = {} + kwargs: dict[str, str] = field(default_factory=dict) send_success_msg: bool max_num_limit: int diff --git a/zhenxun/utils/github_utils/models.py b/zhenxun/utils/github_utils/models.py index 91a0776e9..4eab3a6da 100644 --- a/zhenxun/utils/github_utils/models.py +++ b/zhenxun/utils/github_utils/models.py @@ -1,3 +1,4 @@ +from dataclasses import field from typing import Protocol from aiocache import cached @@ -99,7 +100,7 @@ class FileInfo(BaseModel): type: FileType name: str - files: list["FileInfo"] = [] + files: list["FileInfo"] = field(default_factory=list) class JsdelivrStrategy: