From ea502c1fff454718a8b3f7f9cca49fff1fc795f3 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 15 Nov 2021 23:05:05 +0800 Subject: [PATCH] :loud_sound: add deprecation warning for toml load --- nonebot/plugin/load.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nonebot/plugin/load.py b/nonebot/plugin/load.py index 5e1002dc..75850f91 100644 --- a/nonebot/plugin/load.py +++ b/nonebot/plugin/load.py @@ -1,4 +1,5 @@ import json +import warnings from typing import Set, Iterable, Optional import tomlkit @@ -113,10 +114,15 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]: with open(file_path, "r", encoding=encoding) as f: data = tomlkit.parse(f.read()) # type: ignore - nonebot_data = data.get("tool", {}).get("nonebot") or data.get( - "nonebot", {}).get("plugins") + nonebot_data = data.get("tool", {}).get("nonebot") if not nonebot_data: - raise ValueError("Cannot find '[tool.nonebot]' in given toml file!") + nonebot_data = data.get("nonebot", {}).get("plugins") + if nonebot_data: + warnings.warn( + "[nonebot.plugins] table are now deprecated. Use [tool.nonebot] instead.", + DeprecationWarning) + else: + raise ValueError("Cannot find '[tool.nonebot]' in given toml file!") plugins = nonebot_data.get("plugins", []) plugin_dirs = nonebot_data.get("plugin_dirs", []) assert isinstance(plugins, list), "plugins must be a list of plugin name"