clean utils
This commit is contained in:
@@ -2,27 +2,18 @@ import yaml
|
||||
from collections.abc import Mapping
|
||||
from dataclasses import asdict
|
||||
|
||||
|
||||
class SaveFileObject():
|
||||
#def __init__(self,d={},**kwargs):
|
||||
# self.data=d
|
||||
# self.data.update(kwargs)
|
||||
#def asdict(self):
|
||||
# return self.data
|
||||
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)
|
||||
#def __getattr__(self, key):
|
||||
# return self.data.get(key,None)
|
||||
#def __setattr__(self, key,value):
|
||||
# if not key in ["data"]:
|
||||
# self.data[key]=value
|
||||
# else:
|
||||
# super().__setattr__(key,value)
|
||||
|
||||
|
||||
class SaveFileMapping(Mapping):
|
||||
__file =None
|
||||
@@ -54,14 +45,12 @@ class SaveFileMapping(Mapping):
|
||||
|
||||
def __getitem__(self,key):
|
||||
return self.data.get(key,None)
|
||||
def __setitem__(self,key,data):
|
||||
|
||||
def __setitem__(self,key,data):
|
||||
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 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")
|
||||
|
||||
self.data[key]= data
|
||||
return self.data[key]
|
||||
|
||||
Reference in New Issue
Block a user