From a2b8dca9ba2a87855586f7b9e35f1c2fd796edf0 Mon Sep 17 00:00:00 2001 From: ny Date: Fri, 10 Jan 2025 17:38:07 +0100 Subject: [PATCH] fix: Change schema init to staticmethods --- SideBot/db/tags.py | 10 ++++++---- SideBot/utils/__init__.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/SideBot/db/tags.py b/SideBot/db/tags.py index fc51d5d..7a6761b 100644 --- a/SideBot/db/tags.py +++ b/SideBot/db/tags.py @@ -13,7 +13,8 @@ class _Tags: """Internal DB class for tags.""" - async def write_schema(self: asyncpg.Connection) -> None: + @staticmethod + async def write_schema(conn: asyncpg.Connection) -> None: for x in [ """ CREATE TYPE public.discorduser AS ( @@ -43,7 +44,7 @@ async def write_schema(self: asyncpg.Connection) -> None: "CREATE INDEX IF NOT EXISTS tags_guild_id_idx ON tags (guild_id, name)", ]: with contextlib.suppress(asyncpg.exceptions.DuplicateObjectError): - await self.execute( + await conn.execute( x, ) @@ -173,11 +174,12 @@ def __init__( self.id = ident self.tags = _Tags(conn) + @staticmethod async def write_schema( - self: asyncpg.Connection, + conn: asyncpg.Connection, ) -> None: """Tag class.""" - await _Tags.write_schema(self) + await _Tags.write_schema(conn) @classmethod async def get( diff --git a/SideBot/utils/__init__.py b/SideBot/utils/__init__.py index a9f480f..507b22b 100644 --- a/SideBot/utils/__init__.py +++ b/SideBot/utils/__init__.py @@ -30,7 +30,7 @@ def as_dict(self): } @classmethod - def from_dict(cls, data: dict): + def from_dict(cls, data: dict) -> "DBConfig": return cls( data["user"], data["pass"], @@ -52,7 +52,7 @@ def __init__(self, token: str, owner: int, db_url: str, cogs: list[str]): self.cogs = cogs @classmethod - def from_dict(cls, data: dict): + def from_dict(cls, data: dict) -> "BotConfig": if "botDB" in data: return cls(data["discordToken"], data["owner"], DBConfig.from_dict(data["botDB"]).connect_str, data["cogs"]) return cls(data["discordToken"], data["owner"], data["botDBURL"], data["cogs"])