From 1b035ed19b1f5946510c5f789faa2687e5135d88 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 10 Jan 2022 22:24:45 +0800 Subject: [PATCH] :fire: add State() deprecation warning --- nonebot/params.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nonebot/params.py b/nonebot/params.py index 2563d9a9..bf6547ef 100644 --- a/nonebot/params.py +++ b/nonebot/params.py @@ -1,5 +1,6 @@ import asyncio import inspect +import warnings from typing_extensions import Literal from typing import Any, Dict, List, Tuple, Callable, Optional, cast from contextlib import AsyncExitStack, contextmanager, asynccontextmanager @@ -278,12 +279,23 @@ def EventToMe() -> bool: return Depends(_event_to_me) +class StateInner(T_State): + ... + + +def State() -> T_State: + warnings.warn("State() is deprecated, use T_State instead", DeprecationWarning) + return StateInner() + + class StateParam(Param): @classmethod def _check_param( cls, dependent: Dependent, name: str, param: inspect.Parameter ) -> Optional["StateParam"]: - if param.default == param.empty: + if isinstance(param.default, StateInner): + return cls(Required) + elif param.default == param.empty: if param.annotation is T_State: return cls(Required) elif param.annotation == param.empty and name == "state":