code cleaning
This commit is contained in:
@@ -36,12 +36,6 @@ class Appliance(IAppliance, metaclass=_MetaAppliance):
|
||||
for feature in cls.__lam_schema__["features"].values():
|
||||
feature.freeze_class()
|
||||
return
|
||||
# print(name)
|
||||
# print("!!!!!!!!!!")
|
||||
# print(cls.__lam_schema__)
|
||||
# print(cls.__lam_schema__["feature"])
|
||||
# return
|
||||
# cls.__lam_schema__["features"] = dict(cls.__lam_schema__["features"])
|
||||
super()._freeze_unknown_field_schema(name)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -13,8 +13,6 @@ class BaseElement:
|
||||
__lam_object_mutable__ = False
|
||||
|
||||
def __setattr__(self, key: str, value: Any):
|
||||
print(f"!guarded_setattr {self} {key} {value}")
|
||||
|
||||
if key.startswith("_"):
|
||||
return super().__setattr__(key, value)
|
||||
|
||||
@@ -74,7 +72,6 @@ class BaseElement:
|
||||
|
||||
@classmethod
|
||||
def freeze_class(cls, force: bool = False):
|
||||
|
||||
if cls.__lam_class_mutable__ or force:
|
||||
cls.validate_schema_class()
|
||||
# class should not have any elements so they are all unknown
|
||||
@@ -101,7 +98,6 @@ class BaseElement:
|
||||
|
||||
@classmethod
|
||||
def validate_schema_class(cls):
|
||||
|
||||
# class should not have any elements so they are all unknown
|
||||
for unknown_attr in {_[0] for _ in cls.__dict__.items() if is_data_attribute(_[0], _[1])}:
|
||||
cls._validate_unknown_attr_class(unknown_attr)
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
from typing import Any, Type
|
||||
from copy import copy
|
||||
from frozendict import frozendict
|
||||
from ..LAMFields.LAMField import LAMField
|
||||
|
||||
# from ..LAMFields.FrozenLAMField import FrozenLAMField
|
||||
from .element import _MetaElement
|
||||
from ..feature import Feature
|
||||
from ..exception import InvalidFieldValue, InvalidFeatureInheritance, InvalidFieldName
|
||||
from ..tools import LAMdeepfreeze
|
||||
|
||||
|
||||
class _MetaAppliance(_MetaElement):
|
||||
@@ -172,14 +168,9 @@ class _MetaAppliance(_MetaElement):
|
||||
for k, v in list(kwargs.items()):
|
||||
if k in cls.__lam_schema__["features"]:
|
||||
base_feat_cls = cls.__lam_schema__["features"][k]
|
||||
# print(f"!!!!! {v}")
|
||||
# print(f"!!!!! {base_feat_cls}")
|
||||
# print(isinstance(v, type))
|
||||
# print(issubclass(v, base_feat_cls))
|
||||
|
||||
# Case 1: subclass replacement (inheritance)
|
||||
if isinstance(v, type) and issubclass(v, base_feat_cls):
|
||||
print("hhhh")
|
||||
v.check_appliance_compatibility(cls)
|
||||
|
||||
# record subclass into instance schema
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from typing import Optional, TypeVar, get_origin, get_args, Dict, Any, Callable, Type, Union
|
||||
from typing import Optional, TypeVar, get_origin, get_args, Any, Type, Union
|
||||
|
||||
from types import FunctionType, UnionType
|
||||
from copy import deepcopy, copy
|
||||
from threading import Lock
|
||||
from copy import deepcopy
|
||||
|
||||
import inspect, ast, textwrap
|
||||
|
||||
@@ -12,7 +11,6 @@ from ..tools import _resolve_annotation, _peel_annotated
|
||||
from ..LAMFields.LAMField import LAMField
|
||||
from ..LAMFields.LAMFieldInfo import LAMFieldInfo
|
||||
|
||||
# from ..LAMFields.FrozenLAMField import FrozenLAMField
|
||||
from ..defines import ALLOWED_HELPERS_MATH, ALLOWED_HELPERS_DEFAULT, ALLOWED_MODEL_FIELDS_TYPES
|
||||
from ..base_element import BaseElement
|
||||
|
||||
@@ -467,9 +465,7 @@ class _MetaElement(type):
|
||||
|
||||
for _fname, _fvalue in fakecls.export().items():
|
||||
field = cls.__lam_schema__[_fname]
|
||||
# field.validate(_fvalue)
|
||||
field.update_value(_fvalue)
|
||||
# cls.__lam_schema__[_fname] = LAMField(_fname, _fvalue, field.annotations, field.info )
|
||||
|
||||
def __new__(
|
||||
mcs: type["_MetaElement"],
|
||||
@@ -519,7 +515,6 @@ class _MetaElement(type):
|
||||
- For new fields: set the freshly built LAMField and record its source.
|
||||
"""
|
||||
for _fname, _fvalue in stack_exts["modified_fields"].items():
|
||||
# cls.__lam_schema__[_fname] = deepcopy(bases[0].__lam_schema__[_fname])
|
||||
cls.__lam_schema__[_fname].update_value(_fvalue)
|
||||
|
||||
for _fname, _fvalue in stack_exts["new_fields"].items():
|
||||
@@ -567,15 +562,9 @@ class _MetaElement(type):
|
||||
for k, v in list(kwargs.items()):
|
||||
if k in cls.__lam_schema__: # regular field
|
||||
field = cls.__lam_schema__[k].clone_unfrozen()
|
||||
# field.validate(v)
|
||||
field.update_value(v)
|
||||
obj.__lam_schema__[k] = field
|
||||
object.__setattr__(obj, k, v)
|
||||
# lam_field = LAMField(k, v, field.annotations, field.info)
|
||||
# if cls.__lam_class_mutable__:
|
||||
# obj.__lam_schema__[k] = lam_field
|
||||
# else:
|
||||
# obj.__lam_schema__[k] = FrozenLAMField(lam_field)
|
||||
kwargs.pop(k)
|
||||
|
||||
if kwargs:
|
||||
@@ -607,8 +596,6 @@ class _MetaElement(type):
|
||||
|
||||
field = cls.__lam_schema__[name]
|
||||
field.update_value(value)
|
||||
# field.validate(value)
|
||||
# cls.__lam_schema__[name] = LAMField(name, value, field.annotations, field.info)
|
||||
return
|
||||
|
||||
def __getattr__(cls, name) -> Any:
|
||||
@@ -617,8 +604,6 @@ class _MetaElement(type):
|
||||
and getattr(cls, "__lam_initialized__")
|
||||
and name in cls.__lam_schema__
|
||||
):
|
||||
# if cls.__lam_class_mutable__:
|
||||
# return cls.__lam_schema__[name].raw_value
|
||||
return cls.__lam_schema__[name].value
|
||||
raise NonExistingField(f"Non existing class attribute: {name}")
|
||||
|
||||
|
||||
@@ -20,6 +20,5 @@ class _MetaFeature(_MetaElement):
|
||||
cls.bind_appliance(stack_exts["kwargs"]["appliance"])
|
||||
|
||||
def finalize_instance(cls: Type, obj: Any, stack_exts: dict[str, Any]):
|
||||
print(f"2GOT {cls}: {cls.__lam_bound_appliance__}")
|
||||
cls.check_appliance_bound()
|
||||
super().finalize_instance(obj, stack_exts)
|
||||
|
||||
Reference in New Issue
Block a user