Skip to content

Commit

Permalink
use flake8
Browse files Browse the repository at this point in the history
see [Half Permanent] Code Quality Improvement #55
removed old files of alconna
  • Loading branch information
BlueGlassBlock committed Dec 15, 2021
1 parent 4e1db4a commit 274c1e5
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 548 deletions.
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
max-line-length = 110
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,

exclude = .git,
__pycache__,
src/test/*,
src/test_old/*
src/graia/ariadne/entry/*
27 changes: 13 additions & 14 deletions src/graia/ariadne/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import graia.ariadne.event.lifecycle
import graia.ariadne.event.message
import graia.ariadne.event.mirai
import graia.ariadne.event.network
import graia.ariadne.event.lifecycle # noqa: F401
import graia.ariadne.event.message # noqa: F401
import graia.ariadne.event.mirai # noqa: F401
import graia.ariadne.event.network # noqa: F401

# init event

ARIADNE_ASCII_LOGO = r"""
_ _
/\ (_) | |
/ \ _ __ _ __ _ __| |_ __ ___
/ /\ \ | '__| |/ _` |/ _` | '_ \ / _ \
/ ____ \| | | | (_| | (_| | | | | __/
/_/ \_\_| |_|\__,_|\__,_|_| |_|\___|
""".lstrip(
ARIADNE_ASCII_LOGO = (
r" _ _ "
r" /\ (_) | | "
r" / \ _ __ _ __ _ __| |_ __ ___ "
r" / /\ \ | '__| |/ _` |/ _` | '_ \ / _ \ "
r" / ____ \| | | | (_| | (_| | | | | __/ "
r" /_/ \_\_| |_|\__,_|\__,_|_| |_|\___| "
).lstrip(
"\n"
)
# remove first newline
) # remove first newline
17 changes: 3 additions & 14 deletions src/graia/ariadne/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@
import functools
import json
from asyncio.events import AbstractEventLoop
from asyncio.exceptions import CancelledError
from asyncio.locks import Event
from asyncio.queues import Queue
from asyncio.tasks import Task
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
Awaitable,
Callable,
Dict,
Optional,
Set,
Union,
)
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Optional, Set, Union

import aiohttp.web_exceptions
from aiohttp import ClientSession, FormData
Expand Down Expand Up @@ -69,7 +58,7 @@ async def wrapped_network_action_callable(self: "Adapter", *args: "P.args", **kw
except aiohttp.web_exceptions.HTTPNotFound:
raise NotSupportedAction(f"{network_action_callable.__name__}: this action not supported")
except aiohttp.web_exceptions.HTTPInternalServerError as e:
self.broadcast.postEvent(RemoteException())
self.broadcast.postEvent(RemoteException(*e.args))
logger.error("An exception has thrown by remote, please check the console!")
raise
except (
Expand All @@ -79,7 +68,7 @@ async def wrapped_network_action_callable(self: "Adapter", *args: "P.args", **kw
):

logger.error(
f"It seems that we post in a wrong way "
"It seems that we post in a wrong way "
f"for the action '{network_action_callable.__name__}', please open a issue."
)
raise
Expand Down
21 changes: 12 additions & 9 deletions src/graia/ariadne/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ async def recallMessage(self, target: Union[Source, BotMessage, int]) -> None:
"""撤回特定的消息; 撤回自己的消息需要在发出后 2 分钟内才能成功撤回; 如果在群组内, 需要撤回他人的消息则需要管理员/群主权限.
Args:
target (Union[Source, BotMessage, int]): 特定信息的 `messageId`, 可以是 `Source` 实例, `BotMessage` 实例或者是单纯的 int 整数.
target (Union[Source, BotMessage, int]): 特定信息的 `messageId`,
可以是 `Source` 实例, `BotMessage` 实例或者是单纯的 int 整数.
Returns:
None: 没有返回.
Expand Down Expand Up @@ -604,7 +605,8 @@ async def setEssence(self, target: Union[Source, BotMessage, int]):
请自行判断消息来源是否为群组.
Args:
target (Union[Source, BotMessage, int]): 特定信息的 `messageId`, 可以是 `Source` 实例, `BotMessage` 实例或者是单纯的 int 整数.
target (Union[Source, BotMessage, int]): 特定信息的 `messageId`,
可以是 `Source` 实例, `BotMessage` 实例或者是单纯的 int 整数.
Returns:
None: 没有返回.
Expand Down Expand Up @@ -798,7 +800,7 @@ async def getFileList(
List[FileInfo]: 返回的文件信息列表.
"""
if isinstance(target, Friend):
raise NotImplementedError(f"Not implemented for friend")
raise NotImplementedError("Not implemented for friend")

target = target.id if isinstance(target, Friend) else target
target = target.id if isinstance(target, Group) else target
Expand Down Expand Up @@ -837,7 +839,7 @@ async def getFileInfo(
FileInfo: 返回的文件信息.
"""
if isinstance(target, Friend):
raise NotImplementedError(f"Not implemented for friend")
raise NotImplementedError("Not implemented for friend")

target = target.id if isinstance(target, Friend) else target
target = target.id if isinstance(target, Group) else target
Expand Down Expand Up @@ -875,7 +877,7 @@ async def makeDirectory(
FileInfo: 新创建文件夹的信息.
"""
if isinstance(target, Friend):
raise NotImplementedError(f"Not implemented for friend")
raise NotImplementedError("Not implemented for friend")

target = target.id if isinstance(target, Friend) else target
target = target.id if isinstance(target, Group) else target
Expand Down Expand Up @@ -911,7 +913,7 @@ async def deleteFile(
None: 没有返回.
"""
if isinstance(target, Friend):
raise NotImplementedError(f"Not implemented for friend")
raise NotImplementedError("Not implemented for friend")

target = target.id if isinstance(target, Friend) else target
target = target.id if isinstance(target, Group) else target
Expand Down Expand Up @@ -946,7 +948,7 @@ async def moveFile(
None: 没有返回.
"""
if isinstance(target, Friend):
raise NotImplementedError(f"Not implemented for friend")
raise NotImplementedError("Not implemented for friend")

target = target.id if isinstance(target, Friend) else target
target = target.id if isinstance(target, Group) else target
Expand Down Expand Up @@ -982,7 +984,7 @@ async def renameFile(
None: 没有返回.
"""
if isinstance(target, Friend):
raise NotImplementedError(f"Not implemented for friend")
raise NotImplementedError("Not implemented for friend")

target = target.id if isinstance(target, Friend) else target
target = target.id if isinstance(target, Group) else target
Expand Down Expand Up @@ -1125,7 +1127,8 @@ def __init__(
connect_info (Union[Adapter, MiraiSession]) 提供与 `mirai-api-http` 交互的信息.
loop (AbstractEventLoop, optional): 事件循环.
broadcast (Broadcast, optional): 被指定的, 外置的事件系统, 即 `Broadcast Control` 实例.
chat_log_config (ChatLogConfig or Literal[False]): 聊天日志的配置, 请移步 `ChatLogConfig` 查看使用方法. 设置为 False 则会完全禁用聊天日志.
chat_log_config (ChatLogConfig or Literal[False]): 聊天日志的配置, 请移步 `ChatLogConfig` 查看使用方法.
设置为 False 则会完全禁用聊天日志.
use_loguru_traceback (bool): 是否注入 loguru 以获得对 traceback.print_exception() 与 sys.excepthook 的完全控制.
use_bypass_listener (bool): 是否注入 BypassListener 以获得子事件监听支持.
await_task (bool): 是否等待所有 Executor 任务完成再退出.
Expand Down
2 changes: 1 addition & 1 deletion src/graia/ariadne/message/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

from ..model import AriadneBaseModel
from ..util import deprecated, gen_subclass
from ..util import gen_subclass
from .element import (
At,
AtAll,
Expand Down
15 changes: 6 additions & 9 deletions src/graia/ariadne/message/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from enum import Enum
from json import dumps as j_dump
from pathlib import Path
from typing import TYPE_CHECKING, Iterable, List, NoReturn, Optional, Union, overload
from typing import TYPE_CHECKING, Iterable, List, NoReturn, Optional, Union

from pydantic import validator
from pydantic.fields import Field
Expand Down Expand Up @@ -149,21 +149,18 @@ class At(Element):
display: Optional[str] = None

def __init__(self, target: Union[int, Member] = ..., **data) -> None:
"""实例化一个 At 消息元素, 用于承载消息中用于提醒/呼唤特定用户的部分.
Args:
target (int): 需要提醒/呼唤的特定用户的 QQ 号(或者说 id.)
"""
if target is not ...:
if isinstance(target, int):
data.update(target=target)
else:
data.update(target=target.id)
super().__init__(**data)

def __init__(self, target: int, **kwargs) -> None:
"""实例化一个 At 消息元素, 用于承载消息中用于提醒/呼唤特定用户的部分.
Args:
target (int): 需要提醒/呼唤的特定用户的 QQ 号(或者说 id.)
"""
super().__init__(target=target, **kwargs)

def __eq__(self, other: "At"):
return isinstance(other, At) and self.target == other.target

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
from typing import TYPE_CHECKING

from arclet.alconna import Alconna, Arpamar
from arclet.alconna.component import ( # noqa: F401
CommandInterface,
Default,
Option,
OptionInterface,
Subcommand,
)
from arclet.alconna.exceptions import ( # noqa: F401
InvalidFormatMap,
InvalidOptionName,
NullName,
ParamsUnmatched,
)
from arclet.alconna.types import AnyDigit, AnyIP, AnyStr, AnyUrl # noqa: F401
from graia.broadcast.entities.dispatcher import BaseDispatcher
from graia.broadcast.interfaces.dispatcher import DispatcherInterface

from ....event.message import MessageEvent
from ...chain import MessageChain
from ...event.message import MessageEvent
from ..chain import MessageChain

if TYPE_CHECKING:

Expand All @@ -20,23 +35,6 @@ class ArpamarProperty:
pass


from arclet.alconna import Alconna, Arpamar
from arclet.alconna.component import (
CommandInterface,
Default,
Option,
OptionInterface,
Subcommand,
)
from arclet.alconna.exceptions import (
InvalidFormatMap,
InvalidOptionName,
NullName,
ParamsUnmatched,
)
from arclet.alconna.types import AnyDigit, AnyIP, AnyStr, AnyUrl


class AlconnaDispatcher(BaseDispatcher):
"""
Alconna的调度器形式
Expand Down
Loading

0 comments on commit 274c1e5

Please sign in to comment.