mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 01:18:19 +08:00
🔥 add State() deprecation warning
This commit is contained in:
parent
ea65ee5b4f
commit
1b035ed19b
@ -1,5 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
|
import warnings
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
from typing import Any, Dict, List, Tuple, Callable, Optional, cast
|
from typing import Any, Dict, List, Tuple, Callable, Optional, cast
|
||||||
from contextlib import AsyncExitStack, contextmanager, asynccontextmanager
|
from contextlib import AsyncExitStack, contextmanager, asynccontextmanager
|
||||||
@ -278,12 +279,23 @@ def EventToMe() -> bool:
|
|||||||
return Depends(_event_to_me)
|
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):
|
class StateParam(Param):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _check_param(
|
def _check_param(
|
||||||
cls, dependent: Dependent, name: str, param: inspect.Parameter
|
cls, dependent: Dependent, name: str, param: inspect.Parameter
|
||||||
) -> Optional["StateParam"]:
|
) -> 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:
|
if param.annotation is T_State:
|
||||||
return cls(Required)
|
return cls(Required)
|
||||||
elif param.annotation == param.empty and name == "state":
|
elif param.annotation == param.empty and name == "state":
|
||||||
|
Loading…
Reference in New Issue
Block a user