Skip to content

Commit b733365

Browse files
author
James Souter
committed
simplify validation of AttributeIOs in Controller
1 parent ccf0444 commit b733365

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/fastcs/controller.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,9 @@ def __init__(
3737

3838
self._bind_attrs()
3939

40-
# TODO, should validation live inside the controller?
4140
ios = ios or []
42-
43-
self.__check_unique(ios)
44-
4541
self._attribute_ref_io_map = {io.ref_type: io for io in ios}
46-
self._validate_io()
47-
48-
def __check_unique(self, ios: Sequence[AttributeIO[T, AttributeIORefT]]):
49-
for ref_type, count in Counter([io.ref_type for io in ios]).items():
50-
if count > 1:
51-
raise RuntimeError(
52-
f"More than one AttributeIO class handles {ref_type.__name__}"
53-
)
42+
self._validate_io(ios)
5443

5544
async def initialise(self):
5645
pass
@@ -155,9 +144,16 @@ class method and a controller instance, so that it can be called from any
155144
elif isinstance(attr, UnboundPut | UnboundScan | UnboundCommand):
156145
setattr(self, attr_name, attr.bind(self))
157146

158-
def _validate_io(self):
147+
def _validate_io(self, ios: Sequence[AttributeIO[T, AttributeIORefT]]):
159148
"""Validate that each Attribute has an AttributeIORef for which the
160-
controller has an associated AttributeIO class."""
149+
controller has an associated AttributeIO class, and that no two AttributeIO
150+
classes handle the same AttributeIORef type"""
151+
for ref_type, count in Counter([io.ref_type for io in ios]).items():
152+
if count > 1:
153+
raise RuntimeError(
154+
f"More than one AttributeIO class handles {ref_type.__name__}"
155+
)
156+
161157
for attr in self.attributes.values():
162158
if not attr.has_io_ref():
163159
continue

0 commit comments

Comments
 (0)