improve
This commit is contained in:
@@ -63,7 +63,7 @@ class ConfigElement:
|
||||
self.main_build_method: T_BaseElement_ConfigMethod_OrderedSet = {}
|
||||
|
||||
def __copy__(self) -> Self:
|
||||
# we cannot seepcopy because of classmethods, so we do a copy++
|
||||
# we cannot deepcopy because of classmethods, so we do a manual enhanced copy
|
||||
cls = self.__class__
|
||||
result = cls.__new__(cls)
|
||||
for k, v in self.__dict__.items():
|
||||
@@ -179,7 +179,7 @@ class BaseFeature(BaseElement, ABC): ...
|
||||
T_Feature = TypeVar("T_Feature", bound=BaseFeature)
|
||||
T_BaseAppliance_Feature_OrderedSet: TypeAlias = dict[type[T_Feature], T_Feature]
|
||||
|
||||
|
||||
"""
|
||||
class MySet(set):
|
||||
def __init__(self, _iter, klass=None):
|
||||
if klass is not None:
|
||||
@@ -187,6 +187,7 @@ class MySet(set):
|
||||
if not isinstance(item, klass):
|
||||
raise Exception("Error")
|
||||
super(MySet, self).__init__(_iter)
|
||||
"""
|
||||
|
||||
|
||||
class BaseAppliance(BaseElement, ABC):
|
||||
@@ -209,8 +210,8 @@ class BaseAppliance(BaseElement, ABC):
|
||||
|
||||
@field_validator("features", mode="after")
|
||||
@classmethod
|
||||
def serialize_features(cls, features: T_BaseAppliance_Feature_OrderedSet) -> dict[str, BaseFeature]:
|
||||
return {str(key.__name__): value for key, value in features.items()}
|
||||
def __serialize_features(cls, features: T_BaseAppliance_Feature_OrderedSet) -> dict[str, BaseFeature]:
|
||||
return {str(key.__name__): value for key, value in features.items()} # or __qualname__
|
||||
|
||||
@NoInstanceMethod
|
||||
@classmethod
|
||||
|
||||
@@ -57,10 +57,8 @@ class MyAppliance(dabmodel.BaseAppliance):
|
||||
values["template_long_name"] = "My appliance template 1 !!"
|
||||
values["template_description"] = """A very nice Appliance 1"""
|
||||
values["ram_size"] = 1024
|
||||
# values["features"][cls.MyFeature] = MyAppliance.MyFeature()
|
||||
# values["features"][cls.MyFeature2] = MyAppliance.MyFeature2()
|
||||
cls.add_feature(MyAppliance.MyFeature())
|
||||
cls.add_feature(MyAppliance.MyFeature2())
|
||||
cls.add_feature(cls.MyFeature())
|
||||
cls.add_feature(cls.MyFeature2())
|
||||
|
||||
|
||||
class MyAppliance2(MyAppliance):
|
||||
@@ -73,7 +71,6 @@ class MyAppliance2(MyAppliance):
|
||||
values["template_short_name"] = "my-app- tem 2"
|
||||
values["template_long_name"] = "My appliance template 2 !!"
|
||||
values["template_description"] = """A very nice Appliance 2"""
|
||||
# del values["features"][MyAppliance.MyFeature]
|
||||
cls.del_feature(MyAppliance.MyFeature)
|
||||
|
||||
|
||||
@@ -100,7 +97,6 @@ class MyAppliance3(dabmodel.BaseAppliance):
|
||||
values["template_long_name"] = "My appliance template 3 !!"
|
||||
values["template_description"] = """A very nice Appliance 3"""
|
||||
values["ram_size"] = 3076
|
||||
# values["features"][cls.MyFeature] = cls.MyFeature()
|
||||
cls.add_feature(cls.MyFeature())
|
||||
|
||||
|
||||
@@ -129,9 +125,10 @@ class TestModel(unittest.TestCase):
|
||||
print(app2.model_dump_json(indent=1))
|
||||
print(app3.model_dump_json(indent=1))
|
||||
|
||||
# app3.add_feature(MyAppliance.MyFeature())
|
||||
# app3.add_feature(MyAppliance.MyFeature())
|
||||
# app3.add_feature(MyAppliance.MyFeature())
|
||||
# print(app3.model_dump_json(indent=1))
|
||||
# app3 = MyAppliance3(dabinst_short_name="my-app-3", template_description="FORCED")
|
||||
# print(app3.model_dump_json(indent=1))
|
||||
print("aaa")
|
||||
tmp_json = app3.model_dump_json(indent=1)
|
||||
print(tmp_json)
|
||||
recreated_obj = MyAppliance3.parse_raw(tmp_json)
|
||||
print(recreated_obj)
|
||||
|
||||
# app3.add_feature(MyAppliance.MyFeature()) # error case (add_feature not callable from instance)
|
||||
|
||||
Reference in New Issue
Block a user