Skip to content

Commit d9b5c52

Browse files
committed
refactor: kook数据类to_dict正确设置by_alias=True,且允许为数据模型单测做准备
1 parent 187db74 commit d9b5c52

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

astrbot/core/platform/sources/kook/kook_types.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,34 @@ def from_dict(cls, raw_data: dict):
7878
def from_json(cls, raw_data: str | bytes | bytearray):
7979
return cls.model_validate_json(raw_data)
8080

81-
def to_dict(self, by_alias=False, exclude_none=True) -> dict:
82-
return self.model_dump(by_alias=by_alias, exclude_none=exclude_none)
81+
def to_dict(
82+
self,
83+
mode: Literal["json", "python"] | str = "python",
84+
by_alias=True,
85+
exclude_none=True,
86+
exclude_unset=False,
87+
) -> dict:
88+
return self.model_dump(
89+
by_alias=by_alias,
90+
exclude_none=exclude_none,
91+
mode=mode,
92+
exclude_unset=exclude_unset,
93+
)
8394

8495
def to_json(
8596
self,
8697
indent: int | None = None,
8798
ensure_ascii=False,
8899
by_alias=True,
89100
exclude_none=True,
101+
exclude_unset=False,
90102
) -> str:
91103
return self.model_dump_json(
92104
indent=indent,
93105
ensure_ascii=ensure_ascii,
94106
by_alias=by_alias,
95107
exclude_none=exclude_none,
108+
exclude_unset=exclude_unset,
96109
)
97110

98111

0 commit comments

Comments
 (0)