Skip to content

Commit

Permalink
<jx3>[feat]support both pydantic v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
HornCopper committed Sep 6, 2024
1 parent e8744cb commit 0ebca22
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plugins/jx3/calculator/online_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from src.plugins.jx3.attributes.api import get_personal_kf, enchant_mapping

import json
import pydantic

inkarsuki_offical_token = Config.hidden.offcial_token

Expand Down Expand Up @@ -163,7 +164,10 @@ async def get_kungfu(kungfu_id: str) -> Union[str, Literal[False]]:
@staticmethod
def convert_to_dict(obj: Any) -> Any:
if isinstance(obj, BaseModel):
return obj.model_dump(by_alias=True)
if pydantic.VERSION.startswith("1"):
return obj.dict(by_alias=True) # Pydantic v1
else:
return obj.model_dump(by_alias=True) # Pydantic v2
elif isinstance(obj, list):
return [JX3PlayerAttributes.convert_to_dict(item) for item in obj]
elif isinstance(obj, dict):
Expand Down

0 comments on commit 0ebca22

Please sign in to comment.