From 6c2500b8bedb4b6068d1895c3503239538a54d05 Mon Sep 17 00:00:00 2001 From: Gary Yendell Date: Tue, 2 Dec 2025 10:35:08 +0000 Subject: [PATCH] Update AttrR.update to take value: Any --- src/fastcs/attributes/attr_r.py | 16 ++++++++++++---- src/fastcs/datatypes/datatype.py | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/fastcs/attributes/attr_r.py b/src/fastcs/attributes/attr_r.py index 458e0ad56..37343c6ae 100644 --- a/src/fastcs/attributes/attr_r.py +++ b/src/fastcs/attributes/attr_r.py @@ -21,7 +21,7 @@ class AttrR(Attribute[DType_T, AttributeIORefT]): - """A read-only ``Attribute``.""" + """A read-only ``Attribute``""" def __init__( self, @@ -44,7 +44,7 @@ def get(self) -> DType_T: """Get the cached value of the attribute.""" return self._value - async def update(self, value: DType_T) -> None: + async def update(self, value: Any) -> None: """Update the value of the attibute This sets the cached value of the attribute presented in the API. It should @@ -54,8 +54,16 @@ async def update(self, value: DType_T) -> None: To request a change to the setpoint of the attribute, use the ``put`` method, which will attempt to apply the change to the underlying source. + Args: + value: The new value of the attribute + + Raises: + ValueError: If the value fails to be validated to DType_T + """ - self.log_event("Attribute set", attribute=self, value=value) + self.log_event( + "Attribute set", value=value, value_type=type(value), attribute=self + ) self._value = self._datatype.validate(value) @@ -66,7 +74,7 @@ async def update(self, value: DType_T) -> None: ) except Exception as e: logger.opt(exception=e).error( - "On update callback failed", attribute=self, value=value + "On update callbacks failed", attribute=self, value=value ) raise diff --git a/src/fastcs/datatypes/datatype.py b/src/fastcs/datatypes/datatype.py index 034a57623..d8ac378c7 100644 --- a/src/fastcs/datatypes/datatype.py +++ b/src/fastcs/datatypes/datatype.py @@ -39,6 +39,15 @@ def validate(self, value: Any) -> DType_T: modify the value passed in and help the cast succeed or after to perform further validation of the coerced type. + Args: + value: The value to validate + + Returns: + The validated value + + Raises: + ValueError: If the value cannot be coerced + """ if isinstance(value, self.dtype): return value