diff --git a/nonebot/adapters/__init__.py b/nonebot/adapters/__init__.py index 45beb1f5..74d26f69 100644 --- a/nonebot/adapters/__init__.py +++ b/nonebot/adapters/__init__.py @@ -22,6 +22,6 @@ except Exception: from ._bot import Bot as Bot from ._event import Event as Event -from ._template import MessageTemplate as MessageTemplate from ._message import Message as Message from ._message import MessageSegment as MessageSegment +from ._template import MessageTemplate as MessageTemplate diff --git a/nonebot/adapters/_bot.py b/nonebot/adapters/_bot.py index ccd59021..b96e31ae 100644 --- a/nonebot/adapters/_bot.py +++ b/nonebot/adapters/_bot.py @@ -2,12 +2,12 @@ import abc import asyncio from functools import partial from typing_extensions import Protocol -from typing import Any, Set, Union, Tuple, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Set, Tuple, Union, Optional from nonebot.log import logger from nonebot.config import Config -from nonebot.typing import T_CallingAPIHook, T_CalledAPIHook -from nonebot.drivers import Driver, HTTPConnection, HTTPResponse +from nonebot.typing import T_CalledAPIHook, T_CallingAPIHook +from nonebot.drivers import Driver, HTTPResponse, HTTPConnection if TYPE_CHECKING: from ._event import Event diff --git a/nonebot/adapters/_message.py b/nonebot/adapters/_message.py index cc7cd377..1f886108 100644 --- a/nonebot/adapters/_message.py +++ b/nonebot/adapters/_message.py @@ -1,7 +1,7 @@ import abc from copy import deepcopy -from dataclasses import dataclass, field, asdict -from typing import (Any, List, Dict, Type, Union, TypeVar, Mapping, Generic, +from dataclasses import field, asdict, dataclass +from typing import (Any, Dict, List, Type, Union, Generic, Mapping, TypeVar, Iterable) from ._template import MessageTemplate diff --git a/nonebot/adapters/_template.py b/nonebot/adapters/_template.py index 3e60d1a1..8f63b6f5 100644 --- a/nonebot/adapters/_template.py +++ b/nonebot/adapters/_template.py @@ -1,8 +1,8 @@ -import functools import operator +import functools from string import Formatter -from typing import (Any, Set, List, Type, Tuple, Union, TypeVar, Mapping, - Generic, Sequence, TYPE_CHECKING) +from typing import (TYPE_CHECKING, Any, Set, List, Type, Tuple, Union, Generic, + Mapping, TypeVar, Sequence) if TYPE_CHECKING: from . import Message diff --git a/nonebot/config.py b/nonebot/config.py index 732146df..05baf53b 100644 --- a/nonebot/config.py +++ b/nonebot/config.py @@ -17,11 +17,12 @@ import os from pathlib import Path from datetime import timedelta from ipaddress import IPv4Address -from typing import Any, Set, Dict, Union, Tuple, Mapping, Optional +from typing import Any, Set, Dict, Tuple, Union, Mapping, Optional from pydantic import BaseSettings, IPvAnyAddress -from pydantic.env_settings import SettingsError, InitSettingsSource, EnvSettingsSource -from pydantic.env_settings import read_env_file, env_file_sentinel, SettingsSourceCallable +from pydantic.env_settings import (SettingsError, EnvSettingsSource, + InitSettingsSource, SettingsSourceCallable, + read_env_file, env_file_sentinel) class CustomEnvSettings(EnvSettingsSource): diff --git a/nonebot/drivers/__init__.py b/nonebot/drivers/__init__.py index 144870cd..d08f6b0c 100644 --- a/nonebot/drivers/__init__.py +++ b/nonebot/drivers/__init__.py @@ -7,8 +7,9 @@ import abc import asyncio -from dataclasses import dataclass, field -from typing import Any, Set, Dict, Type, Union, Optional, Callable, Awaitable, TYPE_CHECKING +from dataclasses import field, dataclass +from typing import (TYPE_CHECKING, Any, Set, Dict, Type, Union, Callable, + Optional, Awaitable) from nonebot.log import logger from nonebot.utils import escape_tag diff --git a/nonebot/log.py b/nonebot/log.py index 1263f6f2..8b1cc38c 100644 --- a/nonebot/log.py +++ b/nonebot/log.py @@ -12,7 +12,7 @@ NoneBot 使用 `loguru`_ 来记录日志信息。 import sys import logging -from typing import Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Union import loguru diff --git a/nonebot/matcher.py b/nonebot/matcher.py index 46884164..291d56cf 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -10,8 +10,8 @@ from types import ModuleType from datetime import datetime from contextvars import ContextVar from collections import defaultdict -from typing import (TYPE_CHECKING, Any, Dict, List, Type, Union, Mapping, - Callable, Iterable, NoReturn, Optional) +from typing import (TYPE_CHECKING, Any, Dict, List, Type, Union, Callable, + NoReturn, Optional) from nonebot.rule import Rule from nonebot.log import logger diff --git a/nonebot/message.py b/nonebot/message.py index a6044d2c..d994dddb 100644 --- a/nonebot/message.py +++ b/nonebot/message.py @@ -7,14 +7,15 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供 import asyncio from datetime import datetime -from typing import Set, Type, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Set, Type, Optional from nonebot.log import logger from nonebot.rule import TrieRule from nonebot.utils import escape_tag -from nonebot.matcher import matchers, Matcher -from nonebot.exception import IgnoredException, StopPropagation, NoLogException -from nonebot.typing import T_State, T_EventPreProcessor, T_RunPreProcessor, T_EventPostProcessor, T_RunPostProcessor +from nonebot.matcher import Matcher, matchers +from nonebot.exception import NoLogException, StopPropagation, IgnoredException +from nonebot.typing import (T_State, T_RunPreProcessor, T_RunPostProcessor, + T_EventPreProcessor, T_EventPostProcessor) if TYPE_CHECKING: from nonebot.adapters import Bot, Event diff --git a/nonebot/permission.py b/nonebot/permission.py index ac99504b..675f546d 100644 --- a/nonebot/permission.py +++ b/nonebot/permission.py @@ -10,7 +10,7 @@ r""" """ import asyncio -from typing import Union, Optional, Callable, NoReturn, Awaitable, TYPE_CHECKING +from typing import TYPE_CHECKING, Union, Callable, NoReturn, Optional, Awaitable from nonebot.utils import run_sync from nonebot.typing import T_PermissionChecker @@ -141,8 +141,8 @@ def USER(*user: str, perm: Optional[Permission] = None): """ async def _user(bot: "Bot", event: "Event") -> bool: - return bool(event.get_session_id() in user and (perm is None or - await perm(bot, event))) + return bool(event.get_session_id() in user and + (perm is None or await perm(bot, event))) return Permission(_user) diff --git a/nonebot/plugin/manager.py b/nonebot/plugin/manager.py index 77189370..b91d932f 100644 --- a/nonebot/plugin/manager.py +++ b/nonebot/plugin/manager.py @@ -8,10 +8,10 @@ from types import ModuleType from collections import Counter from contextvars import ContextVar from importlib.abc import MetaPathFinder -from typing import Set, List, Optional, Iterable +from typing import Set, List, Iterable, Optional from importlib.machinery import PathFinder, SourceFileLoader -from .export import _export, Export +from .export import Export, _export _current_plugin: ContextVar[Optional[ModuleType]] = ContextVar( "_current_plugin", default=None) diff --git a/nonebot/plugins/echo.py b/nonebot/plugins/echo.py index bf4e9619..5e61fd95 100644 --- a/nonebot/plugins/echo.py +++ b/nonebot/plugins/echo.py @@ -3,7 +3,8 @@ from functools import reduce from nonebot.rule import to_me from nonebot.plugin import on_command from nonebot.permission import SUPERUSER -from nonebot.adapters.cqhttp import Bot, unescape, MessageEvent, Message, MessageSegment +from nonebot.adapters.cqhttp import (Bot, Message, MessageEvent, MessageSegment, + unescape) say = on_command("say", to_me(), permission=SUPERUSER) diff --git a/nonebot/plugins/single_session.py b/nonebot/plugins/single_session.py index 5124f7cb..8a8b3cfb 100644 --- a/nonebot/plugins/single_session.py +++ b/nonebot/plugins/single_session.py @@ -3,7 +3,8 @@ from typing import Dict, Optional from nonebot.typing import T_State from nonebot.matcher import Matcher from nonebot.adapters import Bot, Event -from nonebot.message import run_preprocessor, run_postprocessor, IgnoredException +from nonebot.message import (IgnoredException, run_preprocessor, + run_postprocessor) _running_matcher: Dict[str, int] = {} diff --git a/nonebot/rule.py b/nonebot/rule.py index ea4ddadb..863339df 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -13,8 +13,10 @@ import re import shlex import asyncio from itertools import product -from argparse import Namespace, ArgumentParser as ArgParser -from typing import Any, Dict, Union, Tuple, Optional, Callable, Sequence, NoReturn, Awaitable, TYPE_CHECKING +from argparse import Namespace +from argparse import ArgumentParser as ArgParser +from typing import (TYPE_CHECKING, Any, Dict, Tuple, Union, Callable, NoReturn, + Optional, Sequence, Awaitable) from pygtrie import CharTrie @@ -25,7 +27,7 @@ from nonebot.exception import ParserExit from nonebot.typing import T_State, T_RuleChecker if TYPE_CHECKING: - from nonebot.adapters import Bot, Event, MessageSegment + from nonebot.adapters import Bot, Event class Rule: diff --git a/nonebot/typing.py b/nonebot/typing.py index 9a5bcf80..273661eb 100644 --- a/nonebot/typing.py +++ b/nonebot/typing.py @@ -18,7 +18,8 @@ https://docs.python.org/3/library/typing.html """ from collections.abc import Callable as BaseCallable -from typing import Any, Dict, Union, TypeVar, Optional, Callable, NoReturn, Awaitable, TYPE_CHECKING +from typing import (TYPE_CHECKING, Any, Dict, Union, TypeVar, Callable, + NoReturn, Optional, Awaitable) if TYPE_CHECKING: from nonebot.matcher import Matcher diff --git a/nonebot/utils.py b/nonebot/utils.py index 7891bdf2..8183986d 100644 --- a/nonebot/utils.py +++ b/nonebot/utils.py @@ -3,7 +3,7 @@ import json import asyncio import dataclasses from functools import wraps, partial -from typing import Any, Optional, Callable, Awaitable +from typing import Any, Callable, Optional, Awaitable from nonebot.log import logger from nonebot.typing import overrides