Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 1, 2024
1 parent 1c7cfad commit dbce493
Show file tree
Hide file tree
Showing 33 changed files with 136 additions and 170 deletions.
1 change: 1 addition & 0 deletions docs/gen_ref.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generate the code reference pages and navigation."""

import sys
from pathlib import Path

Expand Down
28 changes: 12 additions & 16 deletions src/graia/ariadne/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ def available(self) -> bool:

def __repr__(self) -> str:
return "<ConnectionStatus {}>".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}",
])
)


Expand All @@ -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 = []
Expand Down
6 changes: 2 additions & 4 deletions src/graia/ariadne/connection/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
6 changes: 2 additions & 4 deletions src/graia/ariadne/connection/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 9 additions & 11 deletions src/graia/ariadne/connection/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/console/saya.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 控制台对 Saya 封装的 Behaviour 与 Schema"""

from dataclasses import dataclass, field
from typing import Callable, List

Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""本模块创建了 Ariadne 中的上下文变量"""

from __future__ import annotations

from contextlib import contextmanager, suppress
Expand Down
1 change: 0 additions & 1 deletion src/graia/ariadne/entry/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Ariadne 消息相关的导入集合"""


from ..message import Quote as Quote
from ..message import Source as Source
from ..message.chain import MessageChain as MessageChain
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/event/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 的事件"""

from graia.broadcast import Dispatchable

from ..dispatcher import BaseDispatcher
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/event/lifecycle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne, Adapter 生命周期相关事件"""

import typing

from graia.broadcast.entities.event import Dispatchable
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/event/message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 消息事件"""

from typing import Any, Dict, List, Optional, Union

from pydantic import Field, root_validator
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/message/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""本模块提供 Ariadne 消息相关部件."""

from datetime import datetime
from typing import TYPE_CHECKING

Expand Down
19 changes: 7 additions & 12 deletions src/graia/ariadne/message/chain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 消息链的实现"""

import re
from copy import deepcopy
from typing import (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
"""
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/message/commander/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Commander: 便捷的指令触发体系"""

import abc
import asyncio
import contextlib
Expand Down
7 changes: 3 additions & 4 deletions src/graia/ariadne/message/element.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 中的消息元素"""

from base64 import b64decode, b64encode
from datetime import datetime
from enum import Enum
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/message/formatter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""基于 format string 的消息链格式化器"""

from __future__ import annotations

import string
Expand Down
6 changes: 4 additions & 2 deletions src/graia/ariadne/message/parser/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 基础的 parser, 包括 DetectPrefix 与 DetectSuffix"""

import abc
import difflib
import fnmatch
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions src/graia/ariadne/message/parser/twilight.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Twilight: 混合式消息链处理器"""

import abc
import contextlib
import enum
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions src/graia/ariadne/message/parser/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""消息链处理器用到的工具函数, 类"""

import argparse
import inspect
import re
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
17 changes: 8 additions & 9 deletions src/graia/ariadne/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 各种 model 存放的位置"""

import functools
from datetime import datetime
from typing import TYPE_CHECKING, Awaitable, Callable, Dict, Literal, Optional, Type, Union
Expand Down Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/model/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""用于 Ariadne 数据模型的工具类."""

from datetime import datetime
from typing import TYPE_CHECKING, Any, Literal, Union
from typing_extensions import NotRequired, TypedDict
Expand Down
29 changes: 12 additions & 17 deletions src/graia/ariadne/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ariadne 的 launart 服务相关"""

import asyncio
import importlib.metadata
import json
Expand Down Expand Up @@ -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}[/]",
])
)


Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit dbce493

Please sign in to comment.