Skip to content

Commit c0c768f

Browse files
committed
Apply suggestions from code review by @bprobert97 - thanks!
1 parent 5c3a39e commit c0c768f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/labthings_fastapi/properties.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,16 @@ def __set__(
679679
680680
This sets the property's value, and notifies any observers.
681681
682+
If property validation is enabled by `.FEATURE_FLAGS.validate_properties_on_set`
683+
this will validate the value against the property's model, and an error
684+
will be raised if the value is not valid.
685+
682686
:param obj: the `.Thing` to which we are attached.
683687
:param value: the new value for the property.
684688
:param emit_changed_event: whether to emit a changed event.
685689
"""
686-
property_info = self.descriptor_info(obj)
687690
if FEATURE_FLAGS.validate_properties_on_set:
691+
property_info = self.descriptor_info(obj)
688692
obj.__dict__[self.name] = property_info.validate(value)
689693
else:
690694
obj.__dict__[self.name] = value
@@ -922,8 +926,8 @@ def __set__(self, obj: Owner, value: Value) -> None:
922926
"""
923927
if self.fset is None:
924928
raise ReadOnlyPropertyError(f"Property {self.name} of {obj} has no setter.")
925-
property_info = self.descriptor_info(obj)
926929
if FEATURE_FLAGS.validate_properties_on_set:
930+
property_info = self.descriptor_info(obj)
927931
value = property_info.validate(value)
928932

929933
self.fset(obj, value)

0 commit comments

Comments
 (0)