Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Add properties for parameter attributes instead of exclusively proces…
Browse files Browse the repository at this point in the history
…sing them on init
  • Loading branch information
mawildoer committed Nov 15, 2024
1 parent f70a067 commit ef42cd2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/faebryk/core/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ef42cd2

Please sign in to comment.