From 6a7758e8f933c29b56943f2f91c994a2729e4ee4 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 4 May 2024 18:27:12 -0400 Subject: [PATCH] fix(aurora): reverted previous change, instead using pydantic's ConfigDicts to resolve the error I was encountering previously --- aurora/models.py | 12 ++++++------ aurora/utilities/factory.py | 10 +++++++--- aurora/utilities/json.py | 4 +--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/aurora/models.py b/aurora/models.py index c90d674..a50aba8 100644 --- a/aurora/models.py +++ b/aurora/models.py @@ -1,8 +1,8 @@ from datetime import datetime, timedelta -from typing import Any, ClassVar, Dict, List, Literal, Optional, Union +from typing import Any, Dict, List, Literal, Optional, Union from discord import Forbidden, HTTPException, InvalidData, NotFound -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from redbot.core.bot import Red from aurora.utilities.utils import generate_dict @@ -10,15 +10,15 @@ from aurora.utilities.utils import generate_dict class AuroraBaseModel(BaseModel): """Base class for all models in Aurora.""" - bot: ClassVar[Red] + model_config = ConfigDict(ignored_types=(Red,)) + bot: Red def to_json(self, indent: int = None, file: Any = None, **kwargs): from aurora.utilities.json import dump, dumps return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs) -class AuroraGuildModel(BaseModel): - """Base class that includes a guild_id attribute, and a modified to_json() method to match.""" - bot: ClassVar[Red] +class AuroraGuildModel(AuroraBaseModel): + """Subclass of AuroraBaseModel that includes a guild_id attribute, and a modified to_json() method to match.""" guild_id: int def to_json(self, indent: int = None, file: Any = None, **kwargs): diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index 823f05c..fdc4126 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -2,13 +2,17 @@ from datetime import datetime, timedelta from typing import Union -from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User +from discord import (Color, Embed, Guild, Interaction, InteractionMessage, + Member, Role, User) from redbot.core import commands -from redbot.core.utils.chat_formatting import bold, box, error, humanize_timedelta, warning +from redbot.core.utils.chat_formatting import (bold, box, error, + humanize_timedelta, warning) from aurora.models import Moderation from aurora.utilities.config import config -from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str +from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict, + get_bool_emoji, get_next_case_number, + get_pagesize_str) async def message_factory( diff --git a/aurora/utilities/json.py b/aurora/utilities/json.py index 7052f90..aad7be7 100644 --- a/aurora/utilities/json.py +++ b/aurora/utilities/json.py @@ -1,7 +1,7 @@ import json from datetime import datetime, timedelta -from aurora.models import AuroraBaseModel, AuroraGuildModel +from aurora.models import AuroraBaseModel class JSONEncoder(json.JSONEncoder): @@ -12,8 +12,6 @@ class JSONEncoder(json.JSONEncoder): return str(o) if isinstance(o, AuroraBaseModel): return o.to_json() - if isinstance(o, AuroraGuildModel): - return o.to_json() return super().default(o)