This commit is contained in:
chacha
2025-09-23 22:27:00 +02:00
parent 71faefcf68
commit 100d2cadcb
7 changed files with 19 additions and 24 deletions

View File

@@ -15,8 +15,8 @@ from .__metadata__ import __version__, __Summuary__, __Name__
from .meta.element import ClassMutable, ObjectMutable
from .element import Element
from .LAMFields.LAMField import LAMField
from .LAMFields.LAMFieldInfo import LAMFieldInfo
from .lam_field.lam_field import LAMField
from .lam_field.lam_field_info import LAMFieldInfo
# from .LAMFields.FrozenLAMField import FrozenLAMField
from .appliance import Appliance

View File

@@ -1,7 +1,7 @@
from typing import Any
# from .LAMFields.FrozenLAMField import FrozenLAMField
from .LAMFields.LAMField import LAMField
from .lam_field.lam_field import LAMField
from .exception import ReadOnlyField, NewFieldForbidden, SchemaViolation
from .tools import LAMdeepfreeze, is_data_attribute

View File

@@ -1,7 +1,8 @@
from typing import Generic, TypeVar, Optional, Any, Self
from typeguard import check_type, CollectionCheckStrategy, TypeCheckError
from .LAMFieldInfo import LAMFieldInfo
from .Constraint import Constraint
from copy import deepcopy
from .lam_field_info import LAMFieldInfo
from .constraint import Constraint
from ..tools import LAMdeepfreeze
from ..exception import InvalidFieldValue, ReadOnlyField
@@ -15,14 +16,11 @@ class LAMField(Generic[TV_LABField]):
def __init__(self, name: str, v: Optional[TV_LABField], a: Any, i: LAMFieldInfo):
self.__name: str = name
self.__source: Optional[type] = None
self.__info: LAMFieldInfo = i
self.__info: LAMFieldInfo = deepcopy(i)
self.__annotations: Any = LAMdeepfreeze(a)
self.validate(v)
self.__default_value: Optional[TV_LABField] = v
self.__value: Optional[TV_LABField] = v
self.__constraints: list[Constraint[Any]] = i.constraints
self.__frozen_constraints_set = False
self.__frozen_constraints = ()
self.__frozen = False
self.__frozen_value = None
self.__frozen_value_set = False
@@ -41,7 +39,7 @@ class LAMField(Generic[TV_LABField]):
def add_source(self, s: type) -> None:
"""Adds source Appliance to the Field"""
if self.__frozen:
raise ReadOnlyField("Field is frozen")
raise ReadOnlyField("Field is frozen, cannot add source now")
self.__source = s
@property
@@ -53,16 +51,12 @@ class LAMField(Generic[TV_LABField]):
"""Adds constraint to the Field"""
if self.__frozen:
raise ReadOnlyField("Field is frozen")
self.__constraints.append(c)
self.__frozen_constraints_set = False
self.__info.add_constraint(c)
@property
def constraints(self) -> list[Constraint]:
"""Returns Field's constraint"""
if not self.__frozen_constraints_set:
self.__frozen_constraints = LAMdeepfreeze(self.__info.constraints)
self.__frozen_value_set = True
return self.__frozen_constraints
return LAMdeepfreeze(self.__info.constraints)
def validate_self(self):
self.validate(self.__value)

View File

@@ -1,24 +1,25 @@
from typing import Optional, Any
from .Constraint import Constraint
from .constraint import Constraint
class LAMFieldInfo:
"""This Class allows to describe a Field in Appliance class"""
def __init__(
self, *, doc: str = "", constraints: Optional[list[Constraint]] = None
):
self._doc: str = doc
def __init__(self, *, doc: str = "", constraints: Optional[list[Constraint]] = None):
self.__doc: str = doc
self.__constraints: list[Constraint]
if constraints is None:
self.__constraints = []
else:
self.__constraints = constraints
def add_constraint(self, constraint: Constraint):
self.__constraints.append(constraint)
@property
def doc(self) -> str:
"""Returns Field's documentation"""
return self._doc
return self.__doc
@property
def constraints(self) -> list[Constraint[Any]]:

View File

@@ -8,8 +8,8 @@ import inspect, ast, textwrap
from typeguard import check_type, TypeCheckError, CollectionCheckStrategy
from frozendict import frozendict
from ..tools import _resolve_annotation, _peel_annotated
from ..LAMFields.LAMField import LAMField
from ..LAMFields.LAMFieldInfo import LAMFieldInfo
from ..lam_field.lam_field import LAMField
from ..lam_field.lam_field_info import LAMFieldInfo
from ..defines import ALLOWED_HELPERS_MATH, ALLOWED_HELPERS_DEFAULT, ALLOWED_MODEL_FIELDS_TYPES
from ..base_element import BaseElement