diff --git a/spec_classes/types/missing.py b/spec_classes/types/missing.py index 7363497..64687fc 100644 --- a/spec_classes/types/missing.py +++ b/spec_classes/types/missing.py @@ -16,6 +16,12 @@ def __bool__(cls): def __call__(cls): return cls + def __hash__(cls): + return id(cls) + + def __eq__(cls, other): + return cls is other + class MISSING(metaclass=_MissingType): """ diff --git a/spec_classes/types/spec_property.py b/spec_classes/types/spec_property.py index 915f466..c7c3194 100644 --- a/spec_classes/types/spec_property.py +++ b/spec_classes/types/spec_property.py @@ -6,6 +6,7 @@ from cached_property import cached_property from spec_classes.errors import NestedAttributeError +from spec_classes.types.missing import EMPTY, MISSING, UNCHANGED from spec_classes.utils.mutation import prepare_attr_value from spec_classes.utils.stackdepth import get_spec_classes_depth from spec_classes.utils.type_checking import check_type, type_label @@ -276,7 +277,7 @@ def __get__(self, instance, owner=None): ) # Store value in cache is cache is enabled - if self.cache: + if self.cache and value not in (MISSING, EMPTY, UNCHANGED): instance.__dict__[self.attr_name] = value return value diff --git a/spec_classes/utils/mutation.py b/spec_classes/utils/mutation.py index c4cbae1..ce199c9 100644 --- a/spec_classes/utils/mutation.py +++ b/spec_classes/utils/mutation.py @@ -227,7 +227,7 @@ def mutate_value( # `replace`; otherwise use MISSING. if new_value not in (MISSING, EMPTY, UNCHANGED): value = new_value - elif new_value is UNCHANGED or not replace: + elif not replace: value = old_value prepare = None # Old values have already been prepared, so we suppress further preparation. else: