Skip to content

Commit

Permalink
style: 更新 Ruff 并重新格式化 (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
st1020 authored Jan 19, 2025
1 parent d535f65 commit f631728
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 42 deletions.
6 changes: 3 additions & 3 deletions alicebot/adapter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
from alicebot.typing import ConfigT, EventT

__all__ = [
"PollingAdapter",
"HttpClientAdapter",
"WebSocketClientAdapter",
"HttpServerAdapter",
"WebSocketServerAdapter",
"PollingAdapter",
"WebSocketAdapter",
"WebSocketClientAdapter",
"WebSocketServerAdapter",
]

logger = structlog.stdlib.get_logger()
Expand Down
2 changes: 1 addition & 1 deletion alicebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def _load_plugins_from_module_name(
else:
for plugin_class, module in plugin_classes:
self._load_plugin_class(
plugin_class, # type: ignore
plugin_class, # type: ignore[type-abstract]
plugin_load_type,
module.__file__,
)
Expand Down
6 changes: 3 additions & 3 deletions alicebot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from pydantic import BaseModel, ConfigDict, DirectoryPath, Field

__all__ = [
"AdapterConfig",
"BotConfig",
"ConfigModel",
"LogConfig",
"BotConfig",
"PluginConfig",
"AdapterConfig",
"MainConfig",
"PluginConfig",
]


Expand Down
8 changes: 4 additions & 4 deletions alicebot/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"""

__all__ = [
"EventException",
"SkipException",
"StopException",
"AdapterException",
"AliceBotException",
"EventException",
"GetEventTimeout",
"AdapterException",
"LoadModuleError",
"SkipException",
"StopException",
]


Expand Down
4 changes: 2 additions & 2 deletions alicebot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
from pydantic_core import core_schema

__all__ = [
"MessageT",
"MessageSegmentT",
"BuildMessageType",
"Message",
"MessageSegment",
"MessageSegmentT",
"MessageT",
]

MessageT = TypeVar("MessageT", bound="Message[Any]")
Expand Down
18 changes: 10 additions & 8 deletions alicebot/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
此模块定义了部分 AliceBot 使用的类型。
"""

# ruff: noqa: A005

from collections.abc import Awaitable
from typing import TYPE_CHECKING, Callable, Optional, TypeVar

Expand All @@ -18,17 +20,17 @@
from alicebot.plugin import Plugin

__all__ = [
"StateT",
"EventT",
"PluginT",
"AdapterHook",
"AdapterT",
"ConfigT",
"MessageT",
"MessageSegmentT",
"BuildMessageType",
"BotHook",
"AdapterHook",
"BuildMessageType",
"ConfigT",
"EventHook",
"EventT",
"MessageSegmentT",
"MessageT",
"PluginT",
"StateT",
]

StateT = TypeVar("StateT")
Expand Down
8 changes: 4 additions & 4 deletions alicebot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

__all__ = [
"ModulePathFinder",
"is_config_class",
"PydanticEncoder",
"get_annotations",
"get_classes_from_module",
"get_classes_from_module_name",
"PydanticEncoder",
"is_config_class",
"samefile",
"sync_func_wrapper",
"sync_ctx_manager_wrapper",
"sync_func_wrapper",
"wrap_get_func",
"get_annotations",
]

_T = TypeVar("_T")
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/global_state_test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async def handle(self) -> None:
if self.bot.global_state.get("count") is None:
self.bot.global_state["count"] = 0
self.bot.global_state["count"] += 1
await self.event.reply(f'add: {self.bot.global_state["count"]}')
await self.event.reply(f"add: {self.bot.global_state['count']}")

async def rule(self) -> bool:
if self.event.adapter.name != "cqhttp":
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/global_state_test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async def handle(self) -> None:
if self.bot.global_state.get("count") is None:
self.bot.global_state["count"] = 0
self.bot.global_state["count"] -= 1
await self.event.reply(f'sub: {self.bot.global_state["count"]}')
await self.event.reply(f"sub: {self.bot.global_state['count']}")

async def rule(self) -> bool:
if self.event.adapter.name != "cqhttp":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from alicebot.exceptions import AdapterException

__all__ = [
"CQHTTPException",
"NetworkError",
"ActionFailed",
"ApiNotAvailable",
"ApiTimeout",
"CQHTTPException",
"NetworkError",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_cqcode(self) -> str:
params = ",".join(
[f"{k}={escape(str(v))}" for k, v in self.data.items() if v is not None]
)
return f'[CQ:{self.type}{"," if params else ""}{params}]'
return f"[CQ:{self.type}{',' if params else ''}{params}]"

@classmethod
def text(cls, text: str) -> Self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if TYPE_CHECKING:
from . import DingTalkAdapter

__all__ = ["UserInfo", "Text", "DingTalkEvent"]
__all__ = ["DingTalkEvent", "Text", "UserInfo"]


class UserInfo(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from alicebot.exceptions import AdapterException

__all__ = ["MiraiException", "NetworkError", "ActionFailed", "ApiTimeout"]
__all__ = ["ActionFailed", "ApiTimeout", "MiraiException", "NetworkError"]


class MiraiException(AdapterException):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from alicebot.exceptions import AdapterException

__all__ = ["OneBotException", "NetworkError", "ActionFailed", "ApiTimeout"]
__all__ = ["ActionFailed", "ApiTimeout", "NetworkError", "OneBotException"]


class OneBotException(AdapterException):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def call_api(
if response_type is None:
return_type_adapter = TypeAdapter(Response[Any])
else:
return_type_adapter = TypeAdapter(Response[response_type]) # type: ignore
return_type_adapter = TypeAdapter(Response[response_type]) # type: ignore[valid-type]

data = self._format_telegram_api_params(**params)
if isinstance(data, aiohttp.FormData):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from alicebot.exceptions import AdapterException

__all__ = ["TelegramException", "NetworkError", "ActionFailed"]
__all__ = ["ActionFailed", "NetworkError", "TelegramException"]


class TelegramException(AdapterException):
Expand Down
2 changes: 1 addition & 1 deletion packages/alicebot-adapter-telegram/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def gen_event(self) -> str:
result = "\n\n".join(
f"""
class {snake_to_camel_case(field.name)}Event(TelegramEvent):
\"\"\"{field.description.removeprefix('Optional. ').split('. ')[0] + '.'}\"\"\"
\"\"\"{field.description.removeprefix("Optional. ").split(". ")[0] + "."}\"\"\"
__event_type__ = "{field.name}"
Expand Down
12 changes: 6 additions & 6 deletions tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def __enter__(self) -> Self:

def __exit__(
self,
__exc_type: Optional[type[BaseException]],
__exc_value: Optional[BaseException],
__traceback: Optional[TracebackType],
_exc_type: Optional[type[BaseException]],
_exc_value: Optional[BaseException],
_traceback: Optional[TracebackType],
) -> None:
nonlocal exit_flag
exit_flag = True
Expand Down Expand Up @@ -125,9 +125,9 @@ async def __aenter__(self) -> Self:

async def __aexit__(
self,
__exc_type: Optional[type[BaseException]],
__exc_value: Optional[BaseException],
__traceback: Optional[TracebackType],
_exc_type: Optional[type[BaseException]],
_exc_value: Optional[BaseException],
_traceback: Optional[TracebackType],
) -> None:
nonlocal exit_flag
exit_flag = True
Expand Down

0 comments on commit f631728

Please sign in to comment.