Skip to content

Commit 25853d4

Browse files
committed
Apply suggestions from code review by @bprobert97 - thanks!
1 parent 51733e9 commit 25853d4

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
@@ -605,12 +605,16 @@ def __set__(
605605
606606
This sets the property's value, and notifies any observers.
607607
608+
If property validation is enabled by `.FEATURE_FLAGS.validate_properties_on_set`
609+
this will validate the value against the property's model, and an error
610+
will be raised if the value is not valid.
611+
608612
:param obj: the `.Thing` to which we are attached.
609613
:param value: the new value for the property.
610614
:param emit_changed_event: whether to emit a changed event.
611615
"""
612-
property_info = self.descriptor_info(obj)
613616
if FEATURE_FLAGS.validate_properties_on_set:
617+
property_info = self.descriptor_info(obj)
614618
obj.__dict__[self.name] = property_info.validate(value)
615619
else:
616620
obj.__dict__[self.name] = value
@@ -827,8 +831,8 @@ def __set__(self, obj: Owner, value: Value) -> None:
827831
"""
828832
if self.fset is None:
829833
raise ReadOnlyPropertyError(f"Property {self.name} of {obj} has no setter.")
830-
property_info = self.descriptor_info(obj)
831834
if FEATURE_FLAGS.validate_properties_on_set:
835+
property_info = self.descriptor_info(obj)
832836
value = property_info.validate(value)
833837

834838
self.fset(obj, value)

0 commit comments

Comments
 (0)