From e7a9466092e039a4bca206c3f47266b33acee9d7 Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Sun, 8 Dec 2024 18:13:48 -0800 Subject: [PATCH] Make all private variables actually private and provide them as properties instead --- token_bot/persistant_database/alert_schema.py | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/token_bot/persistant_database/alert_schema.py b/token_bot/persistant_database/alert_schema.py index 8c20785..4890e4d 100644 --- a/token_bot/persistant_database/alert_schema.py +++ b/token_bot/persistant_database/alert_schema.py @@ -15,13 +15,13 @@ class Alert: self, alert: pdb.AlertType, flavor: Flavor, region: Region, price: int = 0 ) -> None: # AlertType is the Primary Key - self.alert_type: pdb.AlertType = alert + self._alert_type: pdb.AlertType = alert # Flavor (Retail, Classic) is the Sort Key - self.flavor: Flavor = flavor - self.region: Region = region - self.price: int = price + self._flavor: Flavor = flavor + self._region: Region = region + self._price: int = price self._loaded: bool = False - self.users: List[pdb.User] = [] + self._users: List[pdb.User] = [] @classmethod def from_item(cls, primary_key: int, sort_key: str, users: List[int]) -> "Alert": @@ -66,6 +66,26 @@ class Alert: self.sort_key_name: self.sort_key, } + @property + def alert_type(self) -> pdb.AlertType: + return self._alert_type + + @property + def flavor(self) -> Flavor: + return self._flavor + + @property + def region(self) -> Region: + return self._region + + @property + def price(self) -> int: + return self._price + + @property + def users(self) -> List[pdb.User]: + return self._users + def __str__(self): return f"{self.alert_type.value}-{self.flavor.value}-{self.region.value}-{self.price}" @@ -110,7 +130,7 @@ class Alert: response = await table.get_item(key=self.key, consistent_read=consistent) except ItemNotFound: return False - self.users = [pdb.User(int(user_id)) for user_id in response["users"]] + self._users = [pdb.User(int(user_id)) for user_id in response["users"]] self._loaded = True return True