Skip to content

Commit 5ee28f9

Browse files
author
James Souter
committed
allow datatype hinting on Attributes with undefined access mode
1 parent 3c0f564 commit 5ee28f9

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/fastcs/util.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ def validate_hinted_attributes(controller: BaseController):
6262
)
6363
if attr_class is not type(attr):
6464
# skip validation if access mode not specified
65-
if attr_class is Attribute and isinstance(attr, Attribute):
66-
continue
67-
raise RuntimeError(
68-
f"Controller '{controller.__class__.__name__}' introspection of hinted "
69-
f"attribute '{name}' does not match defined access mode. "
70-
f"Expected '{attr_class.__name__}', got '{type(attr).__name__}'."
71-
)
65+
if not (attr_class is Attribute and isinstance(attr, Attribute)):
66+
raise RuntimeError(
67+
f"Controller '{controller.__class__.__name__}' introspection of "
68+
f"hinted attribute '{name}' does not match defined access mode. "
69+
f"Expected '{attr_class.__name__}', got '{type(attr).__name__}'."
70+
)
7271
if attr_dtype is not None and attr_dtype != attr.datatype.dtype:
7372
raise RuntimeError(
7473
f"Controller '{controller.__class__.__name__}' introspection of hinted "

tests/test_util.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,14 @@ async def initialise(self):
186186
await controller.initialise()
187187
# no assertion thrown
188188
validate_hinted_attributes(controller)
189+
190+
class ControllerUnspecifiedAccessModeWrongType(Controller):
191+
unspecified_access_mode_wrong_type: Attribute[int]
192+
193+
async def initialise(self):
194+
self.unspecified_access_mode_wrong_type = AttrRW(Float())
195+
196+
controller = ControllerUnspecifiedAccessModeWrongType()
197+
await controller.initialise()
198+
with pytest.raises(RuntimeError, match="does not match defined datatype"):
199+
validate_hinted_attributes(controller)

0 commit comments

Comments
 (0)