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 Apr 1, 2024
1 parent e4248fc commit 2bdc00a
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 67 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
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
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
1 change: 1 addition & 0 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
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
7 changes: 3 additions & 4 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 @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions src/graia/ariadne/typing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Ariadne 的类型标注"""


import contextlib
import enum
import sys
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion src/graia/ariadne/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""本模块提供 Ariadne 内部使用的小工具, 以及方便的辅助模块."""


# Utility Layout
import functools
import inspect
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/util/async_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
提示: 若需要代替, 建议使用 `unsync` 库.
"""

import asyncio
import functools
import importlib
Expand Down
8 changes: 4 additions & 4 deletions src/graia/ariadne/util/cooldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 4 additions & 6 deletions src/graia/ariadne/util/interrupt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Broadcast Interrupt 相关的工具"""

import asyncio
from typing import Awaitable, Callable, Generic, List, Optional, Type, TypeVar, cast
from typing_extensions import overload
Expand Down Expand Up @@ -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, 如果超时则返回默认值
Expand Down
1 change: 1 addition & 0 deletions src/graia/ariadne/util/saya.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Saya 相关的工具"""

from __future__ import annotations

import inspect
Expand Down
7 changes: 3 additions & 4 deletions src/graia/ariadne/util/send.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""本模块包含许多用于 Ariadne.SendMessage 的 action 函数"""

from typing import Optional, TypeVar, Union, overload

from ..app import Ariadne
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions src/test_old/commander_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 2bdc00a

Please sign in to comment.