From 5db979bb8e0b759fc934ae82dd4d1638589f5421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=80=E5=BE=8B=E7=BA=AF?= Date: Sat, 2 Mar 2024 14:38:04 +0800 Subject: [PATCH] chore(lint): format with ruff --- iamai/bot.py | 7 +++---- iamai/message.py | 13 +++++++------ iamai/utils.py | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/iamai/bot.py b/iamai/bot.py index b41372cf..6ff4a952 100644 --- a/iamai/bot.py +++ b/iamai/bot.py @@ -86,9 +86,7 @@ class Bot: plugin_state: Dict[str, Any] global_state: Dict[Any, Any] - _condition: ( - asyncio.Condition - ) # Condition used to handle get # pyright: ignore[reportUninitializedInstanceVariable] + _condition: asyncio.Condition # Condition used to handle get # pyright: ignore[reportUninitializedInstanceVariable] _current_event: Optional[Event[Any]] # Event currently pending _restart_flag: bool # Restart flag @@ -769,7 +767,7 @@ def load_plugins( """Load the plugin. Args: - *plugins: ``Plugin`` class, plugin module name or plug-in module file path. + *plugins: ``Plugin`` class, plugin module name or plug-in module file path. Type can be ``Type[Plugin]``, ``str`` or ``pathlib.Path``. If it is ``Type[Plugin]``, it will be loaded as a plug-in class. If it is of type ``str``, it will be loaded as the plug-in module name, and the format is the same as the Python ``import`` statement. @@ -780,6 +778,7 @@ def load_plugins( self._extend_plugins.extend(plugins) return self._load_plugins(*plugins) + def _load_plugins_from_dirs(self, *dirs: Path) -> None: """Load plug-ins from the directory. Plug-ins in modules starting with ``_`` will not be imported. The path can be a relative path or an absolute path. diff --git a/iamai/message.py b/iamai/message.py index 148cf2d1..6585b0de 100644 --- a/iamai/message.py +++ b/iamai/message.py @@ -333,7 +333,7 @@ class MessageSegment(ABC, BaseModel, Mapping[str, Any], Generic[MessageT]): Attributes: type: message field type. data: message field content. - """ + """ type: str data: Dict[str, Any] = Field(default_factory=dict) @@ -357,7 +357,7 @@ def from_str(cls, msg: str) -> Self: Returns: Message fields converted by ``str``. - """ + """ @classmethod def from_mapping(cls, msg: Mapping[Any, Any]) -> Self: @@ -458,8 +458,9 @@ def __eq__(self, other: object) -> bool: and self.type == other.type and self.data == other.data ) + def __ne__(self, other: object) -> bool: - """Determine whether they are not equal. + """Determine whether they are not equal. Args: other: other objects. @@ -467,7 +468,7 @@ def __ne__(self, other: object) -> bool: Returns: Whether they are not equal. """ - return not self.__eq__(other) + return not self.__eq__(other) def __add__(self, other: Any) -> MessageT: """Method for adding custom message fields to other objects. @@ -508,9 +509,9 @@ def items(self) -> ItemsView[str, Any]: return self.data.items() def is_text(self) -> bool: - """ is a plain text message field. + """is a plain text message field. Returns: Whether it is a plain text message field. """ - return self.type == "text" \ No newline at end of file + return self.type == "text" diff --git a/iamai/utils.py b/iamai/utils.py index 91e9ab95..bf38302a 100644 --- a/iamai/utils.py +++ b/iamai/utils.py @@ -230,7 +230,7 @@ async def sync_ctx_manager_wrapper( def wrap_get_func( - func: Optional[Callable[[EventT], Union[bool, Awaitable[bool]]]] + func: Optional[Callable[[EventT], Union[bool, Awaitable[bool]]]], ) -> Callable[[EventT], Awaitable[bool]]: """Wrap the parameters accepted by the ``get()`` function into an asynchronous function. @@ -252,7 +252,7 @@ def wrap_get_func( else: # pragma: no cover def get_annotations( - obj: Union[Callable[..., object], Type[Any], ModuleType] + obj: Union[Callable[..., object], Type[Any], ModuleType], ) -> Dict[str, Any]: """Compute the annotation dictionary of an object.