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/__init__.py b/src/graia/ariadne/connection/__init__.py index c14c2946..2b9e1e68 100644 --- a/src/graia/ariadne/connection/__init__.py +++ b/src/graia/ariadne/connection/__init__.py @@ -41,14 +41,12 @@ def available(self) -> bool: def __repr__(self) -> str: return "".format( - " ".join( - [ - f"connected={self.connected}", - f"alive={self.alive}", - f"verified={self.session_key is not None}", - f"stage={self.stage}", - ] - ) + " ".join([ + f"connected={self.connected}", + f"alive={self.alive}", + f"verified={self.session_key is not None}", + f"stage={self.stage}", + ]) ) @@ -70,14 +68,12 @@ def stages(self): return {} def __init__(self, info: T_Info) -> None: - self.id = ".".join( - [ - "elizabeth", - "connection", - str(info.account), - camel_to_snake(self.__class__.__qualname__), - ] - ) + self.id = ".".join([ + "elizabeth", + "connection", + str(info.account), + camel_to_snake(self.__class__.__qualname__), + ]) self.info = info self.fallback = None self.event_callbacks = [] 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/connection/ws.py b/src/graia/ariadne/connection/ws.py index bd9a3e17..f431cd4e 100644 --- a/src/graia/ariadne/connection/ws.py +++ b/src/graia/ariadne/connection/ws.py @@ -147,17 +147,15 @@ async def _(self, io: AbstractWebsocketIO) -> None: if req.query_params.get(k) != v: return await io.extra(WSConnectionClose) await io.extra(WSConnectionAccept) - await io.send( - { - "syncId": "#", - "command": "verify", - "content": { - "verifyKey": self.info.verify_key, - "sessionKey": None, - "qq": self.info.account, - }, - } - ) + await io.send({ + "syncId": "#", + "command": "verify", + "content": { + "verifyKey": self.info.verify_key, + "sessionKey": None, + "qq": self.info.account, + }, + }) self.ws_io = io 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..7d0ad90e 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 @@ -58,15 +59,13 @@ def __init__( user_seg = "{event.sender.nickname}({event.sender.id})" group_seg = "{event.sender.group.name}({event.sender.group.id})" client_seg = "{event.sender.platform}({event.sender.id})" - self.update( - { - GroupMessage: f"{account_seg}: [RECV][{group_seg}] {sender_seg} -> {msg_chain_seg}", - TempMessage: f"{account_seg}: [RECV][{group_seg}:{sender_seg}] -> {msg_chain_seg}", - FriendMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}", - StrangerMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}", - OtherClientMessage: f"{account_seg}: [RECV][{client_seg}] -> {msg_chain_seg}", - } - ) + self.update({ + GroupMessage: f"{account_seg}: [RECV][{group_seg}] {sender_seg} -> {msg_chain_seg}", + TempMessage: f"{account_seg}: [RECV][{group_seg}:{sender_seg}] -> {msg_chain_seg}", + FriendMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}", + StrangerMessage: f"{account_seg}: [RECV][{user_seg}] -> {msg_chain_seg}", + OtherClientMessage: f"{account_seg}: [RECV][{client_seg}] -> {msg_chain_seg}", + }) for active_msg_cls in gen_subclass(ActiveMessage): label: str = "[SYNC] " if active_msg_cls.__fields__["sync"].default else "[SEND]" self[active_msg_cls] = f"{account_seg}: {label}[{{event.subject}}] <- {msg_chain_seg}" 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..05625054 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 @@ -41,13 +42,11 @@ async def check_update(session: ClientSession, name: str, current: str, output: logger.warning(f"Failed to retrieve latest version of {name}: {e}") if result_version > current_version: output.append( - " ".join( - [ - f"[cyan]{name}[/]:" if name.startswith("graiax-") else f"[magenta]{name}[/]:", - f"[green]{current}[/]", - f"-> [yellow]{result}[/]", - ] - ) + " ".join([ + f"[cyan]{name}[/]:" if name.startswith("graiax-") else f"[magenta]{name}[/]:", + f"[green]{current}[/]", + f"-> [yellow]{result}[/]", + ]) ) @@ -95,12 +94,10 @@ def base_telemetry() -> None: output: List[str] = [""] dist_map: Dict[str, str] = get_dist_map() output.extend( - " ".join( - [ - f"[blue]{name}[/]:" if name.startswith("graiax-") else f"[magenta]{name}[/]:", - f"[green]{version}[/]", - ] - ) + " ".join([ + f"[blue]{name}[/]:" if name.startswith("graiax-") else f"[magenta]{name}[/]:", + f"[green]{version}[/]", + ]) for name, version in dist_map.items() ) output.sort() @@ -246,12 +243,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/message/chain.py b/src/test/message/chain.py index 0eb8acf0..31958ed1 100644 --- a/src/test/message/chain.py +++ b/src/test/message/chain.py @@ -288,17 +288,15 @@ def test_list_method(): assert msg_chain.index(Quote) is None # extend - assert msg_chain.extend(Plain("hi"), MessageChain(["good"]), ["why"], "obj", copy=True) == MessageChain( - [ - Plain("Hello World!"), - Plain("How are you?"), - At(12345), - Plain("hi"), - Plain("good"), - Plain("why"), - Plain("obj"), - ] - ) + assert msg_chain.extend(Plain("hi"), MessageChain(["good"]), ["why"], "obj", copy=True) == MessageChain([ + Plain("Hello World!"), + Plain("How are you?"), + At(12345), + Plain("hi"), + Plain("good"), + Plain("why"), + Plain("obj"), + ]) # append msg_chain.append("yo") diff --git a/src/test_old/app.py b/src/test_old/app.py index 9e6123b3..348feeed 100644 --- a/src/test_old/app.py +++ b/src/test_old/app.py @@ -129,14 +129,12 @@ async def raise_(app: Ariadne, ev: MessageEvent): @bcc.receiver( MessageEvent, dispatchers=[ - Twilight( - [ - FullMatch(".test"), - "help" @ ArgumentMatch("--help", "-h", action="store_true"), - "arg" @ WildcardMatch().flags(re.DOTALL), - "verbose" @ ArgumentMatch("--verbose", action="store_true"), - ] - ) + Twilight([ + FullMatch(".test"), + "help" @ ArgumentMatch("--help", "-h", action="store_true"), + "arg" @ WildcardMatch().flags(re.DOTALL), + "verbose" @ ArgumentMatch("--verbose", action="store_true"), + ]) ], ) async def reply1( 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 diff --git a/src/test_old/twilight.py b/src/test_old/twilight.py index 6783e2b0..3c241098 100644 --- a/src/test_old/twilight.py +++ b/src/test_old/twilight.py @@ -7,24 +7,20 @@ install() if __name__ == "__main__": - twilight_args_kwargs = Twilight( - [ - FullMatch(".command"), - 1 @ ArgumentMatch("--option"), - ElementMatch(type=At).param(2), - ] - ) + twilight_args_kwargs = Twilight([ + FullMatch(".command"), + 1 @ ArgumentMatch("--option"), + ElementMatch(type=At).param(2), + ]) sparkle_kwargs = twilight_args_kwargs.generate(MessageChain(".command --option foo ", At(123))) devtools.debug(sparkle_kwargs) - twilight_g = Twilight( - [ - FullMatch(".command"), - "boolean" @ ArgumentMatch("--option", action="store_true"), - ElementMatch(type=At).param("at"), - ] - ) + twilight_g = Twilight([ + FullMatch(".command"), + "boolean" @ ArgumentMatch("--option", action="store_true"), + ElementMatch(type=At).param("at"), + ]) sparkle_kwargs = twilight_g.generate(MessageChain(".command --option ", At(123))) devtools.debug(sparkle_kwargs) @@ -55,15 +51,13 @@ devtools.debug(sp) - flag_twi = Twilight( - [ - FullMatch(".test").help("匹配 .test"), - "op" << ParamMatch().help("操作符"), - "help" @ ArgumentMatch("--help", "-h", action="store_true").help("显示该帮助"), - "arg" @ WildcardMatch().flags(re.DOTALL), - "v" << ArgumentMatch("--verbose", "-v", action="store_true").help("显示详细信息"), - ] - ).help(".test ", "描述", "总结", brief="测试测试!") + flag_twi = Twilight([ + FullMatch(".test").help("匹配 .test"), + "op" << ParamMatch().help("操作符"), + "help" @ ArgumentMatch("--help", "-h", action="store_true").help("显示该帮助"), + "arg" @ WildcardMatch().flags(re.DOTALL), + "v" << ArgumentMatch("--verbose", "-v", action="store_true").help("显示详细信息"), + ]).help(".test ", "描述", "总结", brief="测试测试!") devtools.debug(flag_twi.generate(MessageChain([".test op"]))) @@ -75,18 +69,16 @@ print(flag_twi.get_help(".test", "描述", "总结")) print( - Twilight( - [ - FullMatch(".test").help("匹配 .test"), - "union" @ UnionMatch("A", "B", "C"), - "at" @ ElementMatch(At), - "op1" @ ParamMatch(), - "op2" @ ParamMatch().help("操作符"), - "help" @ ArgumentMatch("--help", "-h", action="store_true").help("显示该帮助"), - "arg" @ WildcardMatch().flags(re.DOTALL), - "v" @ ArgumentMatch("--verbose", "-v", action="store_true").help("显示详细信息"), - ] - ).get_help("用法字符串", "描述", "总结") + Twilight([ + FullMatch(".test").help("匹配 .test"), + "union" @ UnionMatch("A", "B", "C"), + "at" @ ElementMatch(At), + "op1" @ ParamMatch(), + "op2" @ ParamMatch().help("操作符"), + "help" @ ArgumentMatch("--help", "-h", action="store_true").help("显示该帮助"), + "arg" @ WildcardMatch().flags(re.DOTALL), + "v" @ ArgumentMatch("--verbose", "-v", action="store_true").help("显示详细信息"), + ]).get_help("用法字符串", "描述", "总结") ) print(TwilightHelpManager.get_help_mgr("global").get_help("全局帮助", prefix_src="description"))