Skip to content

Commit db37f8b

Browse files
authored
Update AttrR.update to take value: Any (#278)
1 parent 1a11c3a commit db37f8b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/fastcs/attributes/attr_r.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class AttrR(Attribute[DType_T, AttributeIORefT]):
24-
"""A read-only ``Attribute``."""
24+
"""A read-only ``Attribute``"""
2525

2626
def __init__(
2727
self,
@@ -44,7 +44,7 @@ def get(self) -> DType_T:
4444
"""Get the cached value of the attribute."""
4545
return self._value
4646

47-
async def update(self, value: DType_T) -> None:
47+
async def update(self, value: Any) -> None:
4848
"""Update the value of the attibute
4949
5050
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:
5454
To request a change to the setpoint of the attribute, use the ``put`` method,
5555
which will attempt to apply the change to the underlying source.
5656
57+
Args:
58+
value: The new value of the attribute
59+
60+
Raises:
61+
ValueError: If the value fails to be validated to DType_T
62+
5763
"""
58-
self.log_event("Attribute set", attribute=self, value=value)
64+
self.log_event(
65+
"Attribute set", value=value, value_type=type(value), attribute=self
66+
)
5967

6068
self._value = self._datatype.validate(value)
6169

@@ -66,7 +74,7 @@ async def update(self, value: DType_T) -> None:
6674
)
6775
except Exception as e:
6876
logger.opt(exception=e).error(
69-
"On update callback failed", attribute=self, value=value
77+
"On update callbacks failed", attribute=self, value=value
7078
)
7179
raise
7280

src/fastcs/datatypes/datatype.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def validate(self, value: Any) -> DType_T:
3939
modify the value passed in and help the cast succeed or after to perform further
4040
validation of the coerced type.
4141
42+
Args:
43+
value: The value to validate
44+
45+
Returns:
46+
The validated value
47+
48+
Raises:
49+
ValueError: If the value cannot be coerced
50+
4251
"""
4352
if isinstance(value, self.dtype):
4453
return value

0 commit comments

Comments
 (0)