From fd349eefed31af4de71667ebdfb0b1ede7c5462a Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Wed, 30 Oct 2024 20:18:28 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E5=A4=8D=E5=8E=9F=20RegistryMeta?= =?UTF-8?q?=20=E7=9A=84=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_bison/platform/platform.py | 17 ++++++++++++++++- nonebot_bison/types.py | 15 --------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/nonebot_bison/platform/platform.py b/nonebot_bison/platform/platform.py index 111adaf..ecbafe6 100644 --- a/nonebot_bison/platform/platform.py +++ b/nonebot_bison/platform/platform.py @@ -16,7 +16,7 @@ from nonebot_plugin_saa import PlatformTarget from ..post import Post from ..utils import Site, ProcessContext from ..plugin_config import plugin_config -from ..types import Tag, Target, RawPost, SubUnit, Category, RegistryMeta +from ..types import Tag, Target, RawPost, SubUnit, Category class CategoryNotSupport(Exception): @@ -29,6 +29,21 @@ class CategoryNotRecognize(Exception): """raise in get_category, when you don't know the category of post""" +class RegistryMeta(type): + def __new__(cls, name, bases, namespace, **kwargs): + return super().__new__(cls, name, bases, namespace) + + def __init__(cls, name, bases, namespace, **kwargs): + if kwargs.get("base"): + # this is the base class + cls.registry = [] + elif not kwargs.get("abstract"): + # this is the subclass + cls.registry.append(cls) + + super().__init__(name, bases, namespace, **kwargs) + + P = ParamSpec("P") R = TypeVar("R") diff --git a/nonebot_bison/types.py b/nonebot_bison/types.py index d90bcd3..0d08bfd 100644 --- a/nonebot_bison/types.py +++ b/nonebot_bison/types.py @@ -58,18 +58,3 @@ class ApiError(Exception): class SubUnit(NamedTuple): sub_target: Target user_sub_infos: list[UserSubInfo] - - -class RegistryMeta(type): - def __new__(cls, name, bases, namespace, **kwargs): - return super().__new__(cls, name, bases, namespace) - - def __init__(cls, name, bases, namespace, **kwargs): - if kwargs.get("base"): - # this is the base class - cls.registry = [] - elif not kwargs.get("abstract"): - # this is the subclass - cls.registry.append(cls) - - super().__init__(name, bases, namespace, **kwargs)