Feature: 为事件响应器添加更多源码信息 (#2351)

This commit is contained in:
Ju4tCode
2023-09-09 13:46:09 +08:00
committed by GitHub
parent 3601a33f20
commit c4716e3e17
9 changed files with 199 additions and 35 deletions

View File

@ -21,6 +21,7 @@ from typing import (
Type,
Tuple,
Union,
Generic,
TypeVar,
Callable,
Optional,
@ -220,6 +221,16 @@ def resolve_dot_notation(
return instance
class classproperty(Generic[T]):
"""类属性装饰器"""
def __init__(self, func: Callable[[Any], T]) -> None:
self.func = func
def __get__(self, instance: Any, owner: Optional[Type[Any]] = None) -> T:
return self.func(type(instance) if owner is None else owner)
class DataclassEncoder(json.JSONEncoder):
"""可以序列化 {ref}`nonebot.adapters.Message`(List[Dataclass]) 的 `JSONEncoder`"""