WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
2 changed files with 9 additions and 3 deletions
Showing only changes of commit db477c4744 - Show all commits

View file

@ -9,14 +9,20 @@ class AuroraBaseModel(BaseModel):
model_config = ConfigDict(ignored_types=(Red,), arbitrary_types_allowed=True) model_config = ConfigDict(ignored_types=(Red,), arbitrary_types_allowed=True)
bot: Red bot: Red
def dump(self) -> dict:
return self.model_dump(exclude={"bot"})
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs): def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
from ..utilities.json import dump, dumps # pylint: disable=cyclic-import from ..utilities.json import dump, dumps # pylint: disable=cyclic-import
return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs) return dump(self.dump(), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs)
class AuroraGuildModel(AuroraBaseModel): class AuroraGuildModel(AuroraBaseModel):
"""Subclass of AuroraBaseModel that includes a guild_id attribute, and a modified to_json() method to match.""" """Subclass of AuroraBaseModel that includes a guild_id attribute, and a modified to_json() method to match."""
guild_id: int guild_id: int
def dump(self) -> dict:
return self.model_dump(exclude={"bot", "guild_id"})
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs): def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
from ..utilities.json import dump, dumps # pylint: disable=cyclic-import from ..utilities.json import dump, dumps # pylint: disable=cyclic-import
return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs) return dump(self.dump(), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs)

View file

@ -13,7 +13,7 @@ class JSONEncoder(json.JSONEncoder):
if isinstance(o, timedelta): if isinstance(o, timedelta):
return str(o) return str(o)
if isinstance(o, AuroraBaseModel): if isinstance(o, AuroraBaseModel):
return o.to_json() return o.dump()
if isinstance(o, Red): if isinstance(o, Red):
return None return None
return super().default(o) return super().default(o)