From a1843bb98a6601e8baffd4eb51ef0a0a49e80ed8 Mon Sep 17 00:00:00 2001 From: suyiiyii Date: Wed, 30 Oct 2024 23:43:18 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BC=98=E5=8C=96=20SiteMeta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_bison/utils/site.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nonebot_bison/utils/site.py b/nonebot_bison/utils/site.py index 82395e6..8dcd371 100644 --- a/nonebot_bison/utils/site.py +++ b/nonebot_bison/utils/site.py @@ -174,10 +174,18 @@ site_manager: dict[str, type["Site"]] = {} class SiteMeta(type): - def __init__(cls, *args, **kwargs): - if hasattr(cls, "name"): - site_manager[cls.name] = cls - super().__init__(*args, **kwargs) + 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._key = kwargs.get("key") + elif not kwargs.get("abstract"): + # this is the subclass + if hasattr(cls, "name"): + site_manager[cls.name] = cls + super().__init__(name, bases, namespace, **kwargs) class Site(metaclass=SiteMeta):