From 39d6140138f308f03c66b68d56721616b618d2d1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 2 Oct 2021 12:45:17 -0700 Subject: [PATCH] Move assert_not_deleted to worms. --- voussoirkit/worms.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/voussoirkit/worms.py b/voussoirkit/worms.py index 4b3a7b2..5f893a6 100644 --- a/voussoirkit/worms.py +++ b/voussoirkit/worms.py @@ -17,6 +17,12 @@ class WormException(Exception): class BadTable(WormException): pass +class DeletedObject(WormException): + ''' + For when thing.deleted == True. + ''' + pass + def slice_before(li, item): index = li.index(item) return li[:index] @@ -489,6 +495,7 @@ class Object: def __init__(self, database): # Used for transaction self._worms_database = database + self.deleted = False def __reinit__(self): ''' @@ -517,3 +524,10 @@ class Object: def __hash__(self): return hash(f'{self.table}.{self.id}') + + def assert_not_deleted(self) -> None: + ''' + Raises DeletedObject if this object is deleted. + ''' + if self.deleted: + raise DeletedObject(self)