From f5515edd5f6089cf559c9df0260cdf83a7bc8d64 Mon Sep 17 00:00:00 2001 From: www Date: Fri, 25 Dec 2020 21:37:21 +0000 Subject: [PATCH] update create new within update --- misc/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/utils.py b/misc/utils.py index fd1238f..1c2edae 100644 --- a/misc/utils.py +++ b/misc/utils.py @@ -11,6 +11,8 @@ class SaveFileObject(): def asdict(self): return asdict(self) def update(self, new): + if new is None: + new=dict() for key, value in new.items(): if hasattr(self, key): setattr(self, key, value) @@ -57,7 +59,7 @@ class SaveFileMapping(Mapping): if not isinstance(data,SaveFileObject): raise TypeError("data elements should be derived from SaveFileObject") if not callable(getattr(data,"asdict",None)): - raise TypeError("Dataelements need a method to_dict that returns a dict") + raise TypeError("Dataelements need a method asdict that returns a dict this should be out of the box if you use dataclasses") #if not callable(getattr(data.__class__,"from_dict",None)): # raise TypeError("Dataelements need a method to_dict that returns a dict")