From accbf57776ec84ed90f871e286d2d0f9b7713972 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 31 May 2021 01:06:56 +0800 Subject: [PATCH] :rotating_light: remove some linter warning --- docs/api/permission.md | 6 +++--- nonebot/__init__.py | 2 ++ nonebot/permission.py | 15 ++++++++------- nonebot/rule.py | 8 ++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docs/api/permission.md b/docs/api/permission.md index fef1b4d2..e99b7e8b 100644 --- a/docs/api/permission.md +++ b/docs/api/permission.md @@ -112,12 +112,12 @@ Permission(async_function, run_sync(sync_function)) * **说明**: 匹配任意 `meta_event` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 meta_event type 的 Matcher。 -## `USER(*user, perm=)` +## `USER(*user, perm=None)` * **说明** - 在白名单内且满足 perm + `event` 的 `session_id` 在白名单内且满足 perm @@ -127,7 +127,7 @@ Permission(async_function, run_sync(sync_function)) * `*user: str`: 白名单 - * `perm: Permission`: 需要同时满足的权限 + * `perm: Optional[Permission]`: 需要同时满足的权限 diff --git a/nonebot/__init__.py b/nonebot/__init__.py index df19fdbc..5040d70b 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -76,6 +76,7 @@ def get_driver() -> Driver: return _driver +# FIXME: app for reverse driver def get_app(): """ :说明: @@ -101,6 +102,7 @@ def get_app(): return driver.server_app +# FIXME: asgi for reverse driver def get_asgi(): """ :说明: diff --git a/nonebot/permission.py b/nonebot/permission.py index de6c6475..69134fac 100644 --- a/nonebot/permission.py +++ b/nonebot/permission.py @@ -1,4 +1,4 @@ -""" +r""" 权限 ==== @@ -128,27 +128,28 @@ METAEVENT = Permission(_metaevent) """ -def USER(*user: str, perm: Permission = Permission()): +def USER(*user: str, perm: Optional[Permission] = None): """ :说明: - 在白名单内且满足 perm + ``event`` 的 ``session_id`` 在白名单内且满足 perm :参数: * ``*user: str``: 白名单 - * ``perm: Permission``: 需要同时满足的权限 + * ``perm: Optional[Permission]``: 需要同时满足的权限 """ async def _user(bot: "Bot", event: "Event") -> bool: - return event.get_session_id() in user and await perm(bot, event) + return event.get_session_id() in user and bool(perm) and await perm( + bot, event) return Permission(_user) async def _superuser(bot: "Bot", event: "Event") -> bool: - return event.get_type() == "message" and event.get_user_id( - ) in bot.config.superusers + return (event.get_type() == "message" and + event.get_user_id() in bot.config.superusers) SUPERUSER = Permission(_superuser) diff --git a/nonebot/rule.py b/nonebot/rule.py index bbc9f34f..990d93d4 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -1,4 +1,4 @@ -""" +r""" 规则 ==== @@ -250,7 +250,7 @@ def keyword(*keywords: str) -> Rule: def command(*cmds: Union[str, Tuple[str, ...]]) -> Rule: - """ + r""" :说明: 命令形式匹配,根据配置里提供的 ``command_start``, ``command_sep`` 判断消息是否为命令。 @@ -321,7 +321,7 @@ class ArgumentParser(ArgParser): def shell_command(*cmds: Union[str, Tuple[str, ...]], parser: Optional[ArgumentParser] = None) -> Rule: - """ + r""" :说明: 支持 ``shell_like`` 解析参数的命令形式匹配,根据配置里提供的 ``command_start``, ``command_sep`` 判断消息是否为命令。 @@ -394,7 +394,7 @@ def shell_command(*cmds: Union[str, Tuple[str, ...]], def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule: - """ + r""" :说明: 根据正则表达式进行匹配。