home · contact · privacy
Re-organize testing.
[plomtask] / plomtask / versioned_attributes.py
index 8861c9834ff3924d6459ced5cb9c69629424bb45..f5e17f3a848dd08f9066155af036a90c2c1b0941 100644 (file)
@@ -17,12 +17,16 @@ class VersionedAttribute:
                  parent: Any, table_name: str, default: str | float) -> None:
         self.parent = parent
         self.table_name = table_name
-        self.default = default
+        self._default = default
         self.history: dict[str, str | float] = {}
+        # NB: For tighter mypy testing, we might prefer self.history to be
+        # dict[str, float] | dict[str, str] instead, but my current coding
+        # knowledge only manages to make that work by adding much further
+        # complexity, so let's leave it at that for now …
 
     def __hash__(self) -> int:
         history_tuples = tuple((k, v) for k, v in self.history.items())
-        hashable = (self.parent.id_, self.table_name, self.default,
+        hashable = (self.parent.id_, self.table_name, self._default,
                     history_tuples)
         return hash(hashable)
 
@@ -31,11 +35,16 @@ class VersionedAttribute:
         """Return most recent timestamp."""
         return sorted(self.history.keys())[-1]
 
+    @property
+    def value_type_name(self) -> str:
+        """Return string of name of attribute value type."""
+        return type(self._default).__name__
+
     @property
     def newest(self) -> str | float:
-        """Return most recent value, or self.default if self.history empty."""
+        """Return most recent value, or self._default if self.history empty."""
         if 0 == len(self.history):
-            return self.default
+            return self._default
         return self.history[self._newest_timestamp]
 
     def reset_timestamp(self, old_str: str, new_str: str) -> None:
@@ -89,7 +98,7 @@ class VersionedAttribute:
             queried_time += ' 23:59:59.999'
         sorted_timestamps = sorted(self.history.keys())
         if 0 == len(sorted_timestamps):
-            return self.default
+            return self._default
         selected_timestamp = sorted_timestamps[0]
         for timestamp in sorted_timestamps[1:]:
             if timestamp > queried_time: