From 6b5a5e53eb2b67307ab012940c2e9b18d0dc7591 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Sat, 11 Dec 2021 17:35:12 +0800 Subject: [PATCH] :fire: remove state factory --- nonebot/matcher.py | 15 --------------- nonebot/plugin/on.py | 32 -------------------------------- nonebot/plugin/on.pyi | 26 -------------------------- website/src/pages/changelog.md | 1 + 4 files changed, 1 insertion(+), 73 deletions(-) diff --git a/nonebot/matcher.py b/nonebot/matcher.py index f7f6cf51..4701ff55 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -162,11 +162,6 @@ class Matcher(metaclass=MatcherMeta): :类型: ``T_State`` :说明: 事件响应器默认状态 """ - _default_state_factory: Optional[T_StateFactory] = None - """ - :类型: ``Optional[T_State]`` - :说明: 事件响应器默认工厂函数 - """ _default_parser: Optional[T_ArgsParser] = None """ @@ -223,7 +218,6 @@ class Matcher(metaclass=MatcherMeta): module: Optional[ModuleType] = None, expire_time: Optional[datetime] = None, default_state: Optional[T_State] = None, - default_state_factory: Optional[T_StateFactory] = None, default_parser: Optional[T_ArgsParser] = None, default_type_updater: Optional[T_TypeUpdater] = None, default_permission_updater: Optional[T_PermissionUpdater] = None, @@ -245,7 +239,6 @@ class Matcher(metaclass=MatcherMeta): * ``plugin: Optional[Plugin]``: 事件响应器所在插件 * ``module: Optional[ModuleType]``: 事件响应器所在模块 * ``default_state: Optional[T_State]``: 默认状态 ``state`` - * ``default_state_factory: Optional[T_StateFactory]``: 默认状态 ``state`` 的工厂函数 * ``expire_time: Optional[datetime]``: 事件响应器最终有效时间点,过时即被删除 :返回: @@ -277,9 +270,6 @@ class Matcher(metaclass=MatcherMeta): "priority": priority, "block": block, "_default_state": default_state or {}, - "_default_state_factory": staticmethod(default_state_factory) - if default_state_factory - else None, "_default_parser": default_parser, "_default_type_updater": default_type_updater, "_default_permission_updater": default_permission_updater, @@ -662,11 +652,6 @@ class Matcher(metaclass=MatcherMeta): s_t = current_state.set(self.state) try: # Refresh preprocess state - self.state = ( - await self._default_state_factory(bot, event) - if self._default_state_factory - else self.state - ) self.state.update(state) while self.handlers: diff --git a/nonebot/plugin/on.py b/nonebot/plugin/on.py index ca7bafef..2c7446e6 100644 --- a/nonebot/plugin/on.py +++ b/nonebot/plugin/on.py @@ -50,7 +50,6 @@ def on( priority: int = 1, block: bool = False, state: Optional[T_State] = None, - state_factory: Optional[T_StateFactory] = None, _depth: int = 0, ) -> Type[Matcher]: """ @@ -68,7 +67,6 @@ def on( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -85,7 +83,6 @@ def on( plugin=_current_plugin.get(), module=_get_matcher_module(_depth + 1), default_state=state, - default_state_factory=state_factory, ) _store_matcher(matcher) return matcher @@ -99,7 +96,6 @@ def on_metaevent( priority: int = 1, block: bool = False, state: Optional[T_State] = None, - state_factory: Optional[T_StateFactory] = None, _depth: int = 0, ) -> Type[Matcher]: """ @@ -115,7 +111,6 @@ def on_metaevent( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -132,7 +127,6 @@ def on_metaevent( plugin=_current_plugin.get(), module=_get_matcher_module(_depth + 1), default_state=state, - default_state_factory=state_factory, ) _store_matcher(matcher) return matcher @@ -147,7 +141,6 @@ def on_message( priority: int = 1, block: bool = True, state: Optional[T_State] = None, - state_factory: Optional[T_StateFactory] = None, _depth: int = 0, ) -> Type[Matcher]: """ @@ -164,7 +157,6 @@ def on_message( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -181,7 +173,6 @@ def on_message( plugin=_current_plugin.get(), module=_get_matcher_module(_depth + 1), default_state=state, - default_state_factory=state_factory, ) _store_matcher(matcher) return matcher @@ -195,7 +186,6 @@ def on_notice( priority: int = 1, block: bool = False, state: Optional[T_State] = None, - state_factory: Optional[T_StateFactory] = None, _depth: int = 0, ) -> Type[Matcher]: """ @@ -211,7 +201,6 @@ def on_notice( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -228,7 +217,6 @@ def on_notice( plugin=_current_plugin.get(), module=_get_matcher_module(_depth + 1), default_state=state, - default_state_factory=state_factory, ) _store_matcher(matcher) return matcher @@ -242,7 +230,6 @@ def on_request( priority: int = 1, block: bool = False, state: Optional[T_State] = None, - state_factory: Optional[T_StateFactory] = None, _depth: int = 0, ) -> Type[Matcher]: """ @@ -258,7 +245,6 @@ def on_request( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -275,7 +261,6 @@ def on_request( plugin=_current_plugin.get(), module=_get_matcher_module(_depth + 1), default_state=state, - default_state_factory=state_factory, ) _store_matcher(matcher) return matcher @@ -304,7 +289,6 @@ def on_startswith( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -336,7 +320,6 @@ def on_endswith( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -366,7 +349,6 @@ def on_keyword( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -400,7 +382,6 @@ def on_command( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -459,7 +440,6 @@ def on_shell_command( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -512,7 +492,6 @@ def on_regex( * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -627,7 +606,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -653,7 +631,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -682,7 +659,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -709,7 +685,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -736,7 +711,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -768,7 +742,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -798,7 +771,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -827,7 +799,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -864,7 +835,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -905,7 +875,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: @@ -941,7 +910,6 @@ class MatcherGroup: * ``priority: int``: 事件响应器优先级 * ``block: bool``: 是否阻止事件向更低优先级传递 * ``state: Optional[T_State]``: 默认 state - * ``state_factory: Optional[T_StateFactory]``: 默认 state 的工厂函数 :返回: diff --git a/nonebot/plugin/on.pyi b/nonebot/plugin/on.pyi index affd285b..bf1222ef 100644 --- a/nonebot/plugin/on.pyi +++ b/nonebot/plugin/on.pyi @@ -17,7 +17,6 @@ def on( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_metaevent( rule: Optional[Union[Rule, T_RuleChecker]] = ..., @@ -27,7 +26,6 @@ def on_metaevent( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_message( rule: Optional[Union[Rule, T_RuleChecker]] = ..., @@ -38,7 +36,6 @@ def on_message( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_notice( rule: Optional[Union[Rule, T_RuleChecker]] = ..., @@ -48,7 +45,6 @@ def on_notice( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_request( rule: Optional[Union[Rule, T_RuleChecker]] = ..., @@ -58,7 +54,6 @@ def on_request( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_startswith( msg: Union[str, Tuple[str, ...]], @@ -71,7 +66,6 @@ def on_startswith( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_endswith( msg: Union[str, Tuple[str, ...]], @@ -84,7 +78,6 @@ def on_endswith( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_keyword( keywords: Set[str], @@ -96,7 +89,6 @@ def on_keyword( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_command( cmd: Union[str, Tuple[str, ...]], @@ -109,7 +101,6 @@ def on_command( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_shell_command( cmd: Union[str, Tuple[str, ...]], @@ -123,7 +114,6 @@ def on_shell_command( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_regex( pattern: str, @@ -136,7 +126,6 @@ def on_regex( priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... class CommandGroup: @@ -151,7 +140,6 @@ class CommandGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ): ... def command( self, @@ -165,7 +153,6 @@ class CommandGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def shell_command( self, @@ -180,7 +167,6 @@ class CommandGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... class MatcherGroup: @@ -195,7 +181,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ): ... def on( self, @@ -208,7 +193,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_metaevent( self, @@ -219,7 +203,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_message( self, @@ -231,7 +214,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_notice( self, @@ -242,7 +224,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_request( self, @@ -253,7 +234,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_startswith( self, @@ -267,7 +247,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_endswith( self, @@ -281,7 +260,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_keyword( self, @@ -294,7 +272,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_command( self, @@ -308,7 +285,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_shell_command( self, @@ -323,7 +299,6 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... def on_regex( self, @@ -337,5 +312,4 @@ class MatcherGroup: priority: int = ..., block: bool = ..., state: Optional[T_State] = ..., - state_factory: Optional[T_StateFactory] = ..., ) -> Type[Matcher]: ... diff --git a/website/src/pages/changelog.md b/website/src/pages/changelog.md index dc07a86a..3a068096 100644 --- a/website/src/pages/changelog.md +++ b/website/src/pages/changelog.md @@ -9,6 +9,7 @@ - 统一 `Processor`, `Rule`, `Permission`, `Processor` 使用 `Handler` - 修改内置 `Rule`, `Permission` 如 `startswith`, `command` 等使用 class 实现 - 更换文档框架 (docusaurus) 以及主题 (docusaurus-theme-nonepress) +- 移除 Matcher `state_factory` 支持 ## v2.0.0a16