From 5f5f41885e7d5b2d3de60a3261651da3195b5047 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 15 Mar 2022 13:37:28 -0700 Subject: [PATCH] Move get_tables into alphabetical order. --- voussoirkit/worms.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 3285972..12181d1 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -154,15 +154,6 @@ class Database(metaclass=abc.ABCMeta): self.sql.commit() self.last_commit_id = RNG.getrandbits(32) - def get_tables(self) -> set[str]: - ''' - Return the set of all table names in the database. - ''' - query = 'SELECT name FROM sqlite_master WHERE type = "table"' - table_rows = self.select(query) - tables = set(name for (name,) in table_rows) - return tables - def delete(self, table, pairs) -> None: if isinstance(table, type) and issubclass(table, Object): table = table.table @@ -267,6 +258,15 @@ class Database(metaclass=abc.ABCMeta): for object_row in object_rows: yield object_class(self, object_row) + def get_tables(self) -> set[str]: + ''' + Return the set of all table names in the database. + ''' + query = 'SELECT name FROM sqlite_master WHERE type = "table"' + table_rows = self.select(query) + tables = set(name for (name,) in table_rows) + return tables + def insert(self, table, data) -> None: if isinstance(table, type) and issubclass(table, Object): table = table.table @@ -597,6 +597,9 @@ class Object(metaclass=abc.ABCMeta): Initialized with a single argument, the requested ID. ''' def __init__(self, database): + ''' + Your subclass should call super().__init__(database). + ''' # Used for transaction self._worms_database = database self.deleted = False @@ -632,6 +635,9 @@ class Object(metaclass=abc.ABCMeta): def assert_not_deleted(self) -> None: ''' Raises DeletedObject if this object is deleted. + + You need to set self.deleted during any method that deletes the object + from the database. ''' if self.deleted: raise DeletedObject(self)