summaryrefslogtreecommitdiff
path: root/python/associateddatastore.py
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2025-05-07 14:48:46 -0400
committerJosh Ferrell <josh@vector35.com>2025-05-07 14:48:46 -0400
commit70abf7ad5fe83dc6b2cf560026b5f099ea1720b6 (patch)
tree6bd76805d834e2ac24c4bc7ec03b089efb8d16bc /python/associateddatastore.py
parentf0c9799e812898d13c4f20fa7617699b69beef8d (diff)
Fix AssociatedDataStore behavior
Diffstat (limited to 'python/associateddatastore.py')
-rw-r--r--python/associateddatastore.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/python/associateddatastore.py b/python/associateddatastore.py
index 0277ffa9..fef32bcd 100644
--- a/python/associateddatastore.py
+++ b/python/associateddatastore.py
@@ -18,7 +18,6 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
-import copy
from typing import Any
@@ -29,18 +28,22 @@ class _AssociatedDataStore(dict):
def set_default(cls, name: str, value: Any):
cls._defaults[name] = value
+ def get(self, key: Any, default: Any = None) -> Any:
+ if key in self.keys():
+ return self[key]
+ if key in self.__class__._defaults:
+ return self.__class__._defaults[key]
+ return default
+
def __getattr__(self, name: str) -> Any:
- if name in self.__dict__:
- return self.__dict__[name]
- if name not in self:
- if name in self.__class__._defaults:
- result = copy.copy(self.__class__._defaults[name])
- self[name] = result
- return result
+ if name in self.keys():
+ return self[name]
+ if name in self.__class__._defaults:
+ return self.__class__._defaults[name]
return self.__getitem__(name)
- def __setattr__(self, name: str, value: Any):
+ def __setattr__(self, name: str, value: Any) -> None:
self.__setitem__(name, value)
- def __delattr__(self, name: str):
+ def __delattr__(self, name: str) -> None:
self.__delitem__(name)