diff --git a/docs/gen_ref.py b/docs/gen_ref.py index a1179e30..e40a1f1c 100644 --- a/docs/gen_ref.py +++ b/docs/gen_ref.py @@ -1,4 +1,5 @@ """Generate the code reference pages and navigation.""" + import sys from pathlib import Path diff --git a/src/graia/ariadne/connection/config.py b/src/graia/ariadne/connection/config.py index b8e2e833..06383ad5 100644 --- a/src/graia/ariadne/connection/config.py +++ b/src/graia/ariadne/connection/config.py @@ -87,13 +87,11 @@ class ConfigTypedDict(TypedDict): @overload -def from_obj(obj: Sequence[ConfigTypedDict]) -> List["Ariadne"]: - ... +def from_obj(obj: Sequence[ConfigTypedDict]) -> List["Ariadne"]: ... @overload -def from_obj(obj: ConfigTypedDict) -> "Ariadne": - ... +def from_obj(obj: ConfigTypedDict) -> "Ariadne": ... def from_obj(obj: Union[ConfigTypedDict, Sequence[ConfigTypedDict]]) -> Union[List["Ariadne"], "Ariadne"]: diff --git a/src/graia/ariadne/connection/util.py b/src/graia/ariadne/connection/util.py index 554aadd9..bd4d63cd 100644 --- a/src/graia/ariadne/connection/util.py +++ b/src/graia/ariadne/connection/util.py @@ -42,13 +42,11 @@ @overload -def validate_response(data: Any, raising: Literal[False]) -> Any | Exception: - ... +def validate_response(data: Any, raising: Literal[False]) -> Any | Exception: ... @overload -def validate_response(data: Any, raising: Literal[True] = True) -> Any: - ... +def validate_response(data: Any, raising: Literal[True] = True) -> Any: ... def validate_response(data: Any, raising: bool = True): diff --git a/src/graia/ariadne/console/saya.py b/src/graia/ariadne/console/saya.py index 6b9538d2..4d61e790 100644 --- a/src/graia/ariadne/console/saya.py +++ b/src/graia/ariadne/console/saya.py @@ -1,4 +1,5 @@ """Ariadne 控制台对 Saya 封装的 Behaviour 与 Schema""" + from dataclasses import dataclass, field from typing import Callable, List diff --git a/src/graia/ariadne/context.py b/src/graia/ariadne/context.py index 3641f294..4b1e6d93 100644 --- a/src/graia/ariadne/context.py +++ b/src/graia/ariadne/context.py @@ -1,4 +1,5 @@ """本模块创建了 Ariadne 中的上下文变量""" + from __future__ import annotations from contextlib import contextmanager, suppress diff --git a/src/graia/ariadne/entry/message.py b/src/graia/ariadne/entry/message.py index 71a1cfaf..add5111d 100644 --- a/src/graia/ariadne/entry/message.py +++ b/src/graia/ariadne/entry/message.py @@ -1,6 +1,5 @@ """Ariadne 消息相关的导入集合""" - from ..message import Quote as Quote from ..message import Source as Source from ..message.chain import MessageChain as MessageChain diff --git a/src/graia/ariadne/event/__init__.py b/src/graia/ariadne/event/__init__.py index 939d3e83..cd5b3937 100644 --- a/src/graia/ariadne/event/__init__.py +++ b/src/graia/ariadne/event/__init__.py @@ -1,4 +1,5 @@ """Ariadne 的事件""" + from graia.broadcast import Dispatchable from ..dispatcher import BaseDispatcher diff --git a/src/graia/ariadne/event/lifecycle.py b/src/graia/ariadne/event/lifecycle.py index a61a3788..d01a799e 100644 --- a/src/graia/ariadne/event/lifecycle.py +++ b/src/graia/ariadne/event/lifecycle.py @@ -1,4 +1,5 @@ """Ariadne, Adapter 生命周期相关事件""" + import typing from graia.broadcast.entities.event import Dispatchable diff --git a/src/graia/ariadne/event/message.py b/src/graia/ariadne/event/message.py index 1c90bc64..5fae176f 100644 --- a/src/graia/ariadne/event/message.py +++ b/src/graia/ariadne/event/message.py @@ -1,4 +1,5 @@ """Ariadne 消息事件""" + from typing import Any, Dict, List, Optional, Union from pydantic import Field, root_validator diff --git a/src/graia/ariadne/message/__init__.py b/src/graia/ariadne/message/__init__.py index 9609df88..8371545e 100644 --- a/src/graia/ariadne/message/__init__.py +++ b/src/graia/ariadne/message/__init__.py @@ -1,4 +1,5 @@ """本模块提供 Ariadne 消息相关部件.""" + from datetime import datetime from typing import TYPE_CHECKING diff --git a/src/graia/ariadne/message/chain.py b/src/graia/ariadne/message/chain.py index 552a8eb4..bc55c56d 100644 --- a/src/graia/ariadne/message/chain.py +++ b/src/graia/ariadne/message/chain.py @@ -1,4 +1,5 @@ """Ariadne 消息链的实现""" + import re from copy import deepcopy from typing import ( @@ -109,12 +110,10 @@ def parse_obj(cls: Type[Self], obj: Union[List[dict], List[Element]]) -> Self: return cls(cls.build_chain(obj), inline=True) @overload - def __init__(self, __root__: Sequence[Element], *, inline: Literal[True]) -> None: - ... + def __init__(self, __root__: Sequence[Element], *, inline: Literal[True]) -> None: ... @overload - def __init__(self, *elements: MessageContainer, inline: Literal[False] = False) -> None: - ... + def __init__(self, *elements: MessageContainer, inline: Literal[False] = False) -> None: ... def __init__( self, @@ -146,20 +145,16 @@ def __repr_args__(self) -> "ReprArgs": return [(None, list(self.content))] @overload - def __getitem__(self, item: Tuple[Type[Element_T], int]) -> List[Element_T]: - ... + def __getitem__(self, item: Tuple[Type[Element_T], int]) -> List[Element_T]: ... @overload - def __getitem__(self, item: Type[Element_T]) -> List[Element_T]: - ... + def __getitem__(self, item: Type[Element_T]) -> List[Element_T]: ... @overload - def __getitem__(self, item: int) -> Element: - ... + def __getitem__(self, item: int) -> Element: ... @overload - def __getitem__(self, item: slice) -> Self: - ... + def __getitem__(self, item: slice) -> Self: ... def __getitem__(self, item: Union[Tuple[Type[Element], int], Type[Element], int, slice]) -> Any: """ diff --git a/src/graia/ariadne/message/commander/__init__.py b/src/graia/ariadne/message/commander/__init__.py index 0f1b14cb..3366596d 100644 --- a/src/graia/ariadne/message/commander/__init__.py +++ b/src/graia/ariadne/message/commander/__init__.py @@ -1,4 +1,5 @@ """Commander: 便捷的指令触发体系""" + import abc import asyncio import contextlib diff --git a/src/graia/ariadne/message/element.py b/src/graia/ariadne/message/element.py index 7b125c83..836fa92a 100644 --- a/src/graia/ariadne/message/element.py +++ b/src/graia/ariadne/message/element.py @@ -1,4 +1,5 @@ """Ariadne 中的消息元素""" + from base64 import b64decode, b64encode from datetime import datetime from enum import Enum @@ -563,12 +564,10 @@ def parse_obj(cls, obj: Any) -> Self: return cls(**obj) @overload - def __getitem__(self, key: int) -> ForwardNode: - ... + def __getitem__(self, key: int) -> ForwardNode: ... @overload - def __getitem__(self, key: slice) -> List[ForwardNode]: - ... + def __getitem__(self, key: slice) -> List[ForwardNode]: ... def __getitem__(self, key: Union[int, slice]) -> Union[ForwardNode, List[ForwardNode]]: return self.node_list[key] diff --git a/src/graia/ariadne/message/formatter.py b/src/graia/ariadne/message/formatter.py index ff81a260..e1688acf 100644 --- a/src/graia/ariadne/message/formatter.py +++ b/src/graia/ariadne/message/formatter.py @@ -1,4 +1,5 @@ """基于 format string 的消息链格式化器""" + from __future__ import annotations import string diff --git a/src/graia/ariadne/message/parser/base.py b/src/graia/ariadne/message/parser/base.py index 88422fa7..e7946afc 100644 --- a/src/graia/ariadne/message/parser/base.py +++ b/src/graia/ariadne/message/parser/base.py @@ -1,4 +1,5 @@ """Ariadne 基础的 parser, 包括 DetectPrefix 与 DetectSuffix""" + import abc import difflib import fnmatch @@ -26,8 +27,9 @@ class ChainDecorator(abc.ABC, Decorator, Derive[MessageChain]): pre = True @abc.abstractmethod - async def __call__(self, chain: MessageChain, interface: DispatcherInterface) -> Optional[MessageChain]: - ... + async def __call__( + self, chain: MessageChain, interface: DispatcherInterface + ) -> Optional[MessageChain]: ... async def target(self, interface: DecoratorInterface): return await self( diff --git a/src/graia/ariadne/message/parser/twilight.py b/src/graia/ariadne/message/parser/twilight.py index 8e4f853f..485e17e6 100644 --- a/src/graia/ariadne/message/parser/twilight.py +++ b/src/graia/ariadne/message/parser/twilight.py @@ -1,4 +1,5 @@ """Twilight: 混合式消息链处理器""" + import abc import contextlib import enum @@ -443,16 +444,13 @@ def __init__(self, match_result: Dict[Union[int, str], MatchResult]): self.res = match_result @overload - def __getitem__(self, item: Union[int, str]) -> MatchResult: - ... + def __getitem__(self, item: Union[int, str]) -> MatchResult: ... @overload - def __getitem__(self, item: Type[int]) -> List[MatchResult]: - ... + def __getitem__(self, item: Type[int]) -> List[MatchResult]: ... @overload - def __getitem__(self, item: Type[str]) -> Dict[str, MatchResult]: - ... + def __getitem__(self, item: Type[str]) -> Dict[str, MatchResult]: ... def __getitem__(self, item: Union[int, str, Type[int], Type[str]]): if not isinstance(item, type): diff --git a/src/graia/ariadne/message/parser/util.py b/src/graia/ariadne/message/parser/util.py index 496bbfb5..9c0d6ea1 100644 --- a/src/graia/ariadne/message/parser/util.py +++ b/src/graia/ariadne/message/parser/util.py @@ -1,4 +1,5 @@ """消息链处理器用到的工具函数, 类""" + import argparse import inspect import re @@ -225,8 +226,7 @@ def get_help( *, prefix_src: Literal["brief", "usage", "description"] = "brief", fmt_cls: Type[argparse.HelpFormatter] = argparse.HelpFormatter, - ) -> str: - ... + ) -> str: ... @overload def get_help( @@ -237,8 +237,7 @@ def get_help( prefix_src: Literal["brief", "usage", "description"] = "brief", fmt_func: Callable[[str], T], fmt_cls: Type[argparse.HelpFormatter] = argparse.HelpFormatter, - ) -> T: - ... + ) -> T: ... def get_help( self, diff --git a/src/graia/ariadne/model/__init__.py b/src/graia/ariadne/model/__init__.py index 4ae5374b..4b0f2f6c 100644 --- a/src/graia/ariadne/model/__init__.py +++ b/src/graia/ariadne/model/__init__.py @@ -1,4 +1,5 @@ """Ariadne 各种 model 存放的位置""" + import functools from datetime import datetime from typing import TYPE_CHECKING, Awaitable, Callable, Dict, Literal, Optional, Type, Union diff --git a/src/graia/ariadne/model/util.py b/src/graia/ariadne/model/util.py index 6fe7167a..ca9c83a5 100644 --- a/src/graia/ariadne/model/util.py +++ b/src/graia/ariadne/model/util.py @@ -1,4 +1,5 @@ """用于 Ariadne 数据模型的工具类.""" + from datetime import datetime from typing import TYPE_CHECKING, Any, Literal, Union from typing_extensions import NotRequired, TypedDict diff --git a/src/graia/ariadne/service.py b/src/graia/ariadne/service.py index 4e949c39..247dda53 100644 --- a/src/graia/ariadne/service.py +++ b/src/graia/ariadne/service.py @@ -1,4 +1,5 @@ """Ariadne 的 launart 服务相关""" + import asyncio import importlib.metadata import json @@ -246,12 +247,10 @@ def loop(self) -> asyncio.AbstractEventLoop: return it(asyncio.AbstractEventLoop) @overload - def get_interface(self, interface_type: Type[ConnectionInterface]) -> ConnectionInterface: - ... + def get_interface(self, interface_type: Type[ConnectionInterface]) -> ConnectionInterface: ... @overload - def get_interface(self, interface_type: type) -> None: - ... + def get_interface(self, interface_type: type) -> None: ... def get_interface(self, interface_type: type): if interface_type is ConnectionInterface: diff --git a/src/graia/ariadne/typing.py b/src/graia/ariadne/typing.py index fba68105..2f33e922 100644 --- a/src/graia/ariadne/typing.py +++ b/src/graia/ariadne/typing.py @@ -1,6 +1,5 @@ """Ariadne 的类型标注""" - import contextlib import enum import sys @@ -116,14 +115,11 @@ async def exception(item: SendMessageException) -> Optional[T]: @runtime_checkable class SendMessageActionProtocol(Protocol[T_co]): - async def param(self, item: SendMessageDict) -> SendMessageDict: - ... + async def param(self, item: SendMessageDict) -> SendMessageDict: ... - async def result(self, item: "ActiveMessage") -> T_co: - ... + async def result(self, item: "ActiveMessage") -> T_co: ... - async def exception(self, item: SendMessageException) -> Any: - ... + async def exception(self, item: SendMessageException) -> Any: ... def generic_issubclass(cls: Any, par: Union[type, Any, Tuple[type, ...]]) -> bool: diff --git a/src/graia/ariadne/util/__init__.py b/src/graia/ariadne/util/__init__.py index 8b60f8ce..94ec65f6 100644 --- a/src/graia/ariadne/util/__init__.py +++ b/src/graia/ariadne/util/__init__.py @@ -1,6 +1,5 @@ """本模块提供 Ariadne 内部使用的小工具, 以及方便的辅助模块.""" - # Utility Layout import functools import inspect diff --git a/src/graia/ariadne/util/async_exec.py b/src/graia/ariadne/util/async_exec.py index 4ea210cf..b6f89654 100644 --- a/src/graia/ariadne/util/async_exec.py +++ b/src/graia/ariadne/util/async_exec.py @@ -2,6 +2,7 @@ 提示: 若需要代替, 建议使用 `unsync` 库. """ + import asyncio import functools import importlib diff --git a/src/graia/ariadne/util/cooldown.py b/src/graia/ariadne/util/cooldown.py index 25542a56..bb152561 100644 --- a/src/graia/ariadne/util/cooldown.py +++ b/src/graia/ariadne/util/cooldown.py @@ -168,13 +168,13 @@ async def afterDispatch( @overload @contextlib.asynccontextmanager - async def trigger(self, target: int) -> AsyncGenerator[Tuple[Optional[datetime], bool], None]: - ... + async def trigger(self, target: int) -> AsyncGenerator[Tuple[Optional[datetime], bool], None]: ... @overload @contextlib.asynccontextmanager - async def trigger(self, target: int, type: Type[T_Time]) -> AsyncGenerator[Tuple[T_Time, bool], None]: - ... + async def trigger( + self, target: int, type: Type[T_Time] + ) -> AsyncGenerator[Tuple[T_Time, bool], None]: ... @contextlib.asynccontextmanager async def trigger( diff --git a/src/graia/ariadne/util/interrupt.py b/src/graia/ariadne/util/interrupt.py index faa4e60e..ed9a3f75 100644 --- a/src/graia/ariadne/util/interrupt.py +++ b/src/graia/ariadne/util/interrupt.py @@ -1,4 +1,5 @@ """Broadcast Interrupt 相关的工具""" + import asyncio from typing import Awaitable, Callable, Generic, List, Optional, Type, TypeVar, cast from typing_extensions import overload @@ -37,16 +38,13 @@ def __init__( self.block_propagation = block_propagation @overload - async def wait(self, timeout: float, default: T) -> T: - ... + async def wait(self, timeout: float, default: T) -> T: ... @overload - async def wait(self, timeout: float, default: Optional[T] = None) -> Optional[T]: - ... + async def wait(self, timeout: float, default: Optional[T] = None) -> Optional[T]: ... @overload - async def wait(self, timeout: None = None) -> T: - ... + async def wait(self, timeout: None = None) -> T: ... async def wait(self, timeout: Optional[float] = None, default: Optional[T] = None): """等待 Waiter, 如果超时则返回默认值 diff --git a/src/graia/ariadne/util/saya.py b/src/graia/ariadne/util/saya.py index 02f96373..2edf5531 100644 --- a/src/graia/ariadne/util/saya.py +++ b/src/graia/ariadne/util/saya.py @@ -1,4 +1,5 @@ """Saya 相关的工具""" + from __future__ import annotations import inspect diff --git a/src/graia/ariadne/util/send.py b/src/graia/ariadne/util/send.py index 57192d81..36688db7 100644 --- a/src/graia/ariadne/util/send.py +++ b/src/graia/ariadne/util/send.py @@ -1,4 +1,5 @@ """本模块包含许多用于 Ariadne.SendMessage 的 action 函数""" + from typing import Optional, TypeVar, Union, overload from ..app import Ariadne @@ -61,12 +62,10 @@ def __init__(self, ignore: bool = False) -> None: @overload @staticmethod - async def exception(item) -> ActiveMessage: - ... + async def exception(item) -> ActiveMessage: ... @overload - async def exception(self, item) -> ActiveMessage: - ... + async def exception(self, item) -> ActiveMessage: ... @staticmethod async def _handle(item: SendMessageException, ignore: bool): diff --git a/src/test_old/commander_performance.py b/src/test_old/commander_performance.py index d26e346c..baafd018 100644 --- a/src/test_old/commander_performance.py +++ b/src/test_old/commander_performance.py @@ -22,8 +22,7 @@ async def m(): for _ in range(handles): @cmd.command(".test foo bar fox mop {v}") - def _(v: At): - ... + def _(v: At): ... async def disp(entry, dispatchers): debug(dispatchers[0].data) @@ -34,8 +33,7 @@ async def disp(entry, dispatchers): await cmd.execute(msg) - async def a(*args, **kwargs): - ... + async def a(*args, **kwargs): ... cmd.broadcast.Executor = a