From c97a78064566658f391f2172e1d971717b370108 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Tue, 6 Aug 2024 14:19:17 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Feature:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=81=97=E6=BC=8F=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=A0=87=E6=B3=A8?= =?UTF-8?q?=20(#2856)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot/internal/matcher/matcher.py | 2 +- nonebot/internal/params.py | 6 +-- nonebot/plugin/on.py | 2 +- nonebot/plugin/on.pyi | 60 ++++++++++++++--------------- tests/test_param.py | 2 +- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/nonebot/internal/matcher/matcher.py b/nonebot/internal/matcher/matcher.py index e188d8e8..e645b786 100644 --- a/nonebot/internal/matcher/matcher.py +++ b/nonebot/internal/matcher/matcher.py @@ -76,7 +76,7 @@ T = TypeVar("T") current_bot: ContextVar[Bot] = ContextVar("current_bot") current_event: ContextVar[Event] = ContextVar("current_event") current_matcher: ContextVar["Matcher"] = ContextVar("current_matcher") -current_handler: ContextVar[Dependent] = ContextVar("current_handler") +current_handler: ContextVar[Dependent[Any]] = ContextVar("current_handler") @dataclass diff --git a/nonebot/internal/params.py b/nonebot/internal/params.py index 0d5b8dd5..66fef4ac 100644 --- a/nonebot/internal/params.py +++ b/nonebot/internal/params.py @@ -102,7 +102,7 @@ class DependParam(Param): """ def __init__( - self, *args, dependent: Dependent, use_cache: bool, **kwargs: Any + self, *args, dependent: Dependent[Any], use_cache: bool, **kwargs: Any ) -> None: super().__init__(*args, **kwargs) self.dependent = dependent @@ -114,7 +114,7 @@ class DependParam(Param): @classmethod def _from_field( cls, - sub_dependent: Dependent, + sub_dependent: Dependent[Any], use_cache: bool, validate: Union[bool, PydanticFieldInfo], ) -> Self: @@ -190,7 +190,7 @@ class DependParam(Param): use_cache: bool = self.use_cache dependency_cache = {} if dependency_cache is None else dependency_cache - sub_dependent: Dependent = self.dependent + sub_dependent = self.dependent call = cast(Callable[..., Any], sub_dependent.call) # solve sub dependency with current cache diff --git a/nonebot/plugin/on.py b/nonebot/plugin/on.py index 5d1774d8..ba8ca6ac 100644 --- a/nonebot/plugin/on.py +++ b/nonebot/plugin/on.py @@ -114,7 +114,7 @@ def on( rule: Optional[Union[Rule, T_RuleChecker]] = None, permission: Optional[Union[Permission, T_PermissionChecker]] = None, *, - handlers: Optional[list[Union[T_Handler, Dependent]]] = None, + handlers: Optional[list[Union[T_Handler, Dependent[Any]]]] = None, temp: bool = False, expire_time: Optional[Union[datetime, timedelta]] = None, priority: int = 1, diff --git a/nonebot/plugin/on.pyi b/nonebot/plugin/on.pyi index c9b9182f..d6fbac9d 100644 --- a/nonebot/plugin/on.pyi +++ b/nonebot/plugin/on.pyi @@ -21,7 +21,7 @@ def on( rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., *, - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -32,7 +32,7 @@ def on_metaevent( rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., *, - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -43,7 +43,7 @@ def on_message( rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., *, - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -54,7 +54,7 @@ def on_notice( rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., *, - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -65,7 +65,7 @@ def on_request( rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., *, - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -78,7 +78,7 @@ def on_startswith( ignorecase: bool = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -91,7 +91,7 @@ def on_endswith( ignorecase: bool = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -104,7 +104,7 @@ def on_fullmatch( ignorecase: bool = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -116,7 +116,7 @@ def on_keyword( rule: Rule | T_RuleChecker | None = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -130,7 +130,7 @@ def on_command( force_whitespace: str | bool | None = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -144,7 +144,7 @@ def on_shell_command( parser: ArgumentParser | None = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -157,7 +157,7 @@ def on_regex( rule: Rule | T_RuleChecker | None = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -169,7 +169,7 @@ def on_type( rule: Rule | T_RuleChecker | None = ..., *, permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -194,7 +194,7 @@ class CommandGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -209,7 +209,7 @@ class CommandGroup(_Group): aliases: set[str | tuple[str, ...]] | None = ..., force_whitespace: str | bool | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -224,7 +224,7 @@ class CommandGroup(_Group): aliases: set[str | tuple[str, ...]] | None = ..., parser: ArgumentParser | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -239,7 +239,7 @@ class MatcherGroup(_Group): type: str = ..., rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -252,7 +252,7 @@ class MatcherGroup(_Group): type: str = ..., rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -264,7 +264,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -276,7 +276,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -288,7 +288,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -300,7 +300,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -314,7 +314,7 @@ class MatcherGroup(_Group): ignorecase: bool = ..., rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -328,7 +328,7 @@ class MatcherGroup(_Group): ignorecase: bool = ..., rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -342,7 +342,7 @@ class MatcherGroup(_Group): ignorecase: bool = ..., rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -355,7 +355,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -370,7 +370,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -385,7 +385,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -399,7 +399,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., @@ -412,7 +412,7 @@ class MatcherGroup(_Group): *, rule: Rule | T_RuleChecker | None = ..., permission: Permission | T_PermissionChecker | None = ..., - handlers: list[T_Handler | Dependent] | None = ..., + handlers: list[T_Handler | Dependent[Any]] | None = ..., temp: bool = ..., expire_time: datetime | timedelta | None = ..., priority: int = ..., diff --git a/tests/test_param.py b/tests/test_param.py index 1be92b6c..80d42ecd 100644 --- a/tests/test_param.py +++ b/tests/test_param.py @@ -574,7 +574,7 @@ async def test_default(app: App): async def test_priority(): from plugins.param.priority import complex_priority - dependent = Dependent.parse( + dependent = Dependent[None].parse( call=complex_priority, allow_types=[ DependParam,