From ef42cd2fffe369608b094487fb355ffc07636564 Mon Sep 17 00:00:00 2001 From: Matthew Wildoer Date: Thu, 14 Nov 2024 21:55:25 -0800 Subject: [PATCH] Add properties for parameter attributes instead of exclusively processing them on init --- src/faebryk/core/parameter.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/faebryk/core/parameter.py b/src/faebryk/core/parameter.py index f43c42ef..6b061c33 100644 --- a/src/faebryk/core/parameter.py +++ b/src/faebryk/core/parameter.py @@ -865,17 +865,10 @@ def __init__( likely_constrained: bool = False, # TODO rename expect_constraits or similiar ): super().__init__() - if within is not None and not within.units.is_compatible_with(units): - raise ValueError("incompatible units") - - if isinstance(within, Range): - within = Ranges(within) - - if isinstance(soft_set, Range): - soft_set = Ranges(soft_set) if not isinstance(units, Unit): raise TypeError("units must be a Unit") + self.units = units self.within = within self.domain = domain @@ -884,6 +877,28 @@ def __init__( self.tolerance_guess = tolerance_guess self.likely_constrained = likely_constrained + @property + def within(self) -> Ranges | None: + return self._within + + @within.setter + def within(self, value: Range | Ranges | None): + if value is not None and not value.units.is_compatible_with(self.units): + raise ValueError("incompatible units") + if isinstance(value, Range): + value = Ranges(value) + self._within = value + + @property + def soft_set(self) -> Ranges | None: + return self._soft_set + + @soft_set.setter + def soft_set(self, value: Range | Ranges | None): + if isinstance(value, Range): + value = Ranges(value) + self._soft_set = value + # Type forwards type All = ParameterOperatable.All type NumberLike = ParameterOperatable.NumberLike