diff --git a/nonebot/__init__.py b/nonebot/__init__.py index 7f19e26d..e5af0caf 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -29,9 +29,10 @@ """ import importlib -import pkg_resources from typing import Any, Dict, Type, Optional +import pkg_resources + from nonebot.adapters import Bot from nonebot.utils import escape_tag from nonebot.config import Env, Config @@ -277,8 +278,25 @@ def run(host: Optional[str] = None, get_driver().run(host, port, *args, **kwargs) -from nonebot.plugin import on_message, on_notice, on_request, on_metaevent, CommandGroup, MatcherGroup -from nonebot.plugin import on_startswith, on_endswith, on_keyword, on_command, on_shell_command, on_regex -from nonebot.plugin import load_plugin, load_plugins, load_all_plugins, load_builtin_plugins -from nonebot.plugin import load_from_json, load_from_toml -from nonebot.plugin import export, require, get_plugin, get_loaded_plugins +from nonebot.plugin import export as export +from nonebot.plugin import require as require +from nonebot.plugin import on_regex as on_regex +from nonebot.plugin import on_notice as on_notice +from nonebot.plugin import get_plugin as get_plugin +from nonebot.plugin import on_command as on_command +from nonebot.plugin import on_keyword as on_keyword +from nonebot.plugin import on_message as on_message +from nonebot.plugin import on_request as on_request +from nonebot.plugin import load_plugin as load_plugin +from nonebot.plugin import on_endswith as on_endswith +from nonebot.plugin import CommandGroup as CommandGroup +from nonebot.plugin import MatcherGroup as MatcherGroup +from nonebot.plugin import load_plugins as load_plugins +from nonebot.plugin import on_metaevent as on_metaevent +from nonebot.plugin import on_startswith as on_startswith +from nonebot.plugin import load_from_json as load_from_json +from nonebot.plugin import load_from_toml as load_from_toml +from nonebot.plugin import load_all_plugins as load_all_plugins +from nonebot.plugin import on_shell_command as on_shell_command +from nonebot.plugin import get_loaded_plugins as get_loaded_plugins +from nonebot.plugin import load_builtin_plugins as load_builtin_plugins diff --git a/nonebot/drivers/quart.py b/nonebot/drivers/quart.py index d105122b..74d5729e 100644 --- a/nonebot/drivers/quart.py +++ b/nonebot/drivers/quart.py @@ -10,20 +10,22 @@ Quart 驱动适配 import asyncio from dataclasses import dataclass -from typing import List, TypeVar, Callable, Coroutine, Optional +from typing import List, TypeVar, Callable, Optional, Coroutine import uvicorn from pydantic import BaseSettings +from nonebot.config import Env from nonebot.log import logger -from nonebot.utils import escape_tag from nonebot.typing import overrides -from nonebot.config import Env, Config as NoneBotConfig -from nonebot.drivers import ReverseDriver, HTTPRequest, WebSocket as BaseWebSocket +from nonebot.utils import escape_tag +from nonebot.config import Config as NoneBotConfig +from nonebot.drivers import HTTPRequest, ReverseDriver +from nonebot.drivers import WebSocket as BaseWebSocket try: - from werkzeug import exceptions from quart import request as _request + import werkzeug.exceptions as exceptions from quart import websocket as _websocket from quart import Quart, Request, Response from quart import Websocket as QuartWebSocket diff --git a/nonebot/plugin/__init__.py b/nonebot/plugin/__init__.py index 1a13f25b..719fa246 100644 --- a/nonebot/plugin/__init__.py +++ b/nonebot/plugin/__init__.py @@ -10,18 +10,22 @@ from types import ModuleType from dataclasses import dataclass from collections import defaultdict from contextvars import Context, copy_context -from typing import Any, Set, List, Dict, Type, Tuple, Union, Optional, TYPE_CHECKING +from typing import (TYPE_CHECKING, Any, Set, Dict, List, Type, Tuple, Union, + Optional) import tomlkit + from nonebot.log import logger -from nonebot.matcher import Matcher from nonebot.handler import Handler +from nonebot.matcher import Matcher from nonebot.utils import escape_tag from nonebot.permission import Permission -from nonebot.typing import T_State, T_StateFactory, T_Handler, T_RuleChecker -from nonebot.rule import Rule, startswith, endswith, keyword, command, shell_command, ArgumentParser, regex +from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_StateFactory +from nonebot.rule import (Rule, ArgumentParser, regex, command, keyword, + endswith, startswith, shell_command) -from .export import Export, export, _export +from .export import Export +from .export import export as export from .manager import PluginManager, _current_plugin if TYPE_CHECKING: @@ -1072,7 +1076,7 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]: - ``Set[Plugin]`` """ with open(file_path, "r", encoding=encoding) as f: - data = tomlkit.parse(f.read()) + data = tomlkit.parse(f.read()) # type: ignore nonebot_data = data.get("nonebot", {}).get("plugins") if not nonebot_data: diff --git a/nonebot/plugin/__init__.pyi b/nonebot/plugin/__init__.pyi index d9b24f40..bf8b071f 100644 --- a/nonebot/plugin/__init__.pyi +++ b/nonebot/plugin/__init__.pyi @@ -1,16 +1,16 @@ import re from types import ModuleType from dataclasses import dataclass -from typing import Set, List, Dict, Type, Tuple, Union, Optional, TYPE_CHECKING +from typing import Set, Dict, List, Type, Tuple, Union, Optional -from nonebot.matcher import Matcher from nonebot.handler import Handler +from nonebot.matcher import Matcher from nonebot.permission import Permission from nonebot.rule import Rule, ArgumentParser -from nonebot.typing import T_State, T_StateFactory, T_Handler, T_RuleChecker +from nonebot.typing import T_State, T_Handler, T_RuleChecker, T_StateFactory -from .export import Export, export -from .manager import PluginManager +from .export import Export +from .export import export as export plugins: Dict[str, "Plugin"] = ... PLUGIN_NAMESPACE: str = ... diff --git a/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/__init__.py b/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/__init__.py index be901d60..74ac3c47 100644 --- a/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/__init__.py +++ b/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/__init__.py @@ -12,7 +12,13 @@ CQHTTP (OneBot) v11 协议适配 from .event import * from .permission import * -from .message import Message, MessageSegment -from .utils import log, escape, unescape, _b2s -from .bot import Bot, _check_at_me, _check_nickname, _check_reply, _handle_api_result -from .exception import CQHTTPAdapterException, ApiNotAvailable, ActionFailed, NetworkError +from .bot import Bot as Bot +from .utils import log as log +from .utils import escape as escape +from .message import Message as Message +from .utils import unescape as unescape +from .exception import ActionFailed as ActionFailed +from .exception import NetworkError as NetworkError +from .message import MessageSegment as MessageSegment +from .exception import ApiNotAvailable as ApiNotAvailable +from .exception import CQHTTPAdapterException as CQHTTPAdapterException diff --git a/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/event.py b/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/event.py index 3fd6ec11..cfa61315 100644 --- a/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/event.py +++ b/packages/nonebot-adapter-cqhttp/nonebot/adapters/cqhttp/event.py @@ -1,11 +1,12 @@ import inspect from typing_extensions import Literal -from typing import Type, List, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, List, Type, Optional from pydantic import BaseModel from pygtrie import StringTrie -from nonebot.utils import escape_tag + from nonebot.typing import overrides +from nonebot.utils import escape_tag from nonebot.exception import NoLogException from nonebot.adapters import Event as BaseEvent diff --git a/packages/nonebot-adapter-ding/nonebot/adapters/ding/__init__.py b/packages/nonebot-adapter-ding/nonebot/adapters/ding/__init__.py index b1901cfb..4bc02382 100644 --- a/packages/nonebot-adapter-ding/nonebot/adapters/ding/__init__.py +++ b/packages/nonebot-adapter-ding/nonebot/adapters/ding/__init__.py @@ -8,9 +8,16 @@ https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p """ -from .utils import log -from .bot import Bot -from .message import Message, MessageSegment -from .event import Event, MessageEvent, PrivateMessageEvent, GroupMessageEvent -from .exception import (DingAdapterException, ApiNotAvailable, NetworkError, - ActionFailed, SessionExpired) +from .bot import Bot as Bot +from .utils import log as log +from .event import Event as Event +from .message import Message as Message +from .event import MessageEvent as MessageEvent +from .exception import ActionFailed as ActionFailed +from .exception import NetworkError as NetworkError +from .message import MessageSegment as MessageSegment +from .exception import SessionExpired as SessionExpired +from .event import GroupMessageEvent as GroupMessageEvent +from .exception import ApiNotAvailable as ApiNotAvailable +from .event import PrivateMessageEvent as PrivateMessageEvent +from .exception import DingAdapterException as DingAdapterException diff --git a/pyproject.toml b/pyproject.toml index 1686ff3c..a4edd0a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,13 @@ all = ["quart", "aiohttp"] # url = "https://mirrors.aliyun.com/pypi/simple/" # default = true +[tool.isort] +line_length = 80 +length_sort = true +skip_gitignore = true +force_sort_within_sections = true +extra_standard_library = "typing_extensions" + [build-system] requires = ["poetry_core>=1.0.0"] build-backend = "poetry.core.masonry.api"