Skip to content

Commit f2e6685

Browse files
committed
Removed Protocol from Handler classes. Renamed Sender to Setter.
1 parent 3135692 commit f2e6685

File tree

8 files changed

+29
-33
lines changed

8 files changed

+29
-33
lines changed

src/fastcs/attributes.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
from collections.abc import Callable
55
from enum import Enum
6-
from typing import Any, Generic, Protocol, runtime_checkable
6+
from typing import Any, Generic
77

88
import fastcs
99

@@ -18,34 +18,30 @@ class AttrMode(Enum):
1818
READ_WRITE = 3
1919

2020

21-
@runtime_checkable
22-
class Sender(Protocol):
23-
"""Protocol for setting the value of an ``Attribute``."""
24-
21+
class _BaseHandler:
2522
async def initialise(self, controller: fastcs.controller.BaseController) -> None:
2623
pass
2724

25+
26+
class Setter(_BaseHandler):
27+
"""Protocol for setting the value of an ``Attribute``."""
28+
2829
async def put(self, attr: AttrW[T], value: T) -> None:
2930
pass
3031

3132

32-
@runtime_checkable
33-
class Updater(Protocol):
33+
class Updater(_BaseHandler):
3434
"""Protocol for updating the cached readback value of an ``Attribute``."""
3535

3636
# If update period is None then the attribute will not be updated as a task.
3737
update_period: float | None = None
3838

39-
async def initialise(self, controller: fastcs.controller.BaseController) -> None:
40-
pass
41-
4239
async def update(self, attr: AttrR) -> None:
4340
pass
4441

4542

46-
@runtime_checkable
47-
class Handler(Sender, Updater, Protocol):
48-
"""Protocol encapsulating both ``Sender`` and ``Updater``."""
43+
class Handler(Setter, Updater):
44+
"""Protocol encapsulating both ``Setter`` and ``Updater``."""
4945

5046
pass
5147

@@ -179,7 +175,7 @@ def __init__(
179175
datatype: DataType[T],
180176
access_mode=AttrMode.WRITE,
181177
group: str | None = None,
182-
handler: Sender | None = None,
178+
handler: Setter | None = None,
183179
description: str | None = None,
184180
) -> None:
185181
super().__init__(
@@ -193,9 +189,9 @@ def __init__(
193189
self._write_display_callbacks: list[AttrCallback[T]] | None = None
194190

195191
if handler is not None:
196-
self._sender = handler
192+
self._setter = handler
197193
else:
198-
self._sender = SimpleHandler()
194+
self._setter = SimpleHandler()
199195

200196
async def process(self, value: T) -> None:
201197
await self.process_without_display_update(value)
@@ -225,8 +221,8 @@ def add_write_display_callback(self, callback: AttrCallback[T]) -> None:
225221
self._write_display_callbacks.append(callback)
226222

227223
@property
228-
def sender(self) -> Sender:
229-
return self._sender
224+
def sender(self) -> Setter:
225+
return self._setter
230226

231227

232228
class AttrRW(AttrR[T], AttrW[T]):

src/fastcs/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from fastcs.cs_methods import Command, Put, Scan
66

7-
from .attributes import AttrR, AttrW, Sender, Updater
7+
from .attributes import AttrR, AttrW, Setter, Updater
88
from .controller import BaseController, Controller
99
from .controller_api import ControllerAPI
1010
from .exceptions import FastCSException
@@ -79,7 +79,7 @@ def _link_put_tasks(controller_api: ControllerAPI) -> None:
7979
def _link_attribute_sender_class(controller_api: ControllerAPI) -> None:
8080
for attr_name, attribute in controller_api.attributes.items():
8181
match attribute:
82-
case AttrW(sender=Sender()):
82+
case AttrW(sender=Setter()):
8383
assert not attribute.has_process_callback(), (
8484
f"Cannot assign both put method and Sender object to {attr_name}"
8585
)

tests/assertable_controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pytest_mock import MockerFixture, MockType
66

7-
from fastcs.attributes import AttrR, Handler, Sender, Updater
7+
from fastcs.attributes import AttrR, Handler, Setter, Updater
88
from fastcs.backend import build_controller_api
99
from fastcs.controller import Controller, SubController
1010
from fastcs.controller_api import ControllerAPI
@@ -22,15 +22,15 @@ async def update(self, attr):
2222
print(f"{self.controller} update {attr}")
2323

2424

25-
class TestSender(Sender):
25+
class TestSetter(Setter):
2626
async def initialise(self, controller) -> None:
2727
self.controller = controller
2828

2929
async def put(self, attr, value):
3030
print(f"{self.controller}: {attr} = {value}")
3131

3232

33-
class TestHandler(Handler, TestUpdater, TestSender):
33+
class TestHandler(Handler, TestUpdater, TestSetter):
3434
pass
3535

3636

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from tests.assertable_controller import (
2424
MyTestController,
2525
TestHandler,
26-
TestSender,
26+
TestSetter,
2727
TestUpdater,
2828
)
2929
from tests.example_p4p_ioc import run as _run_p4p_ioc
@@ -37,7 +37,7 @@ class BackendTestController(MyTestController):
3737
read_write_int: AttrRW = AttrRW(Int(), handler=TestHandler())
3838
read_write_float: AttrRW = AttrRW(Float())
3939
read_bool: AttrR = AttrR(Bool())
40-
write_bool: AttrW = AttrW(Bool(), handler=TestSender())
40+
write_bool: AttrW = AttrW(Bool(), handler=TestSetter())
4141
read_string: AttrRW = AttrRW(String())
4242

4343

tests/transport/epics/ca/test_softioc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
AssertableControllerAPI,
99
MyTestController,
1010
TestHandler,
11-
TestSender,
11+
TestSetter,
1212
TestUpdater,
1313
)
1414
from tests.util import ColourEnum
@@ -187,7 +187,7 @@ class EpicsController(MyTestController):
187187
read_write_int = AttrRW(Int(), handler=TestHandler())
188188
read_write_float = AttrRW(Float())
189189
read_bool = AttrR(Bool())
190-
write_bool = AttrW(Bool(), handler=TestSender())
190+
write_bool = AttrW(Bool(), handler=TestSetter())
191191
read_string = AttrRW(String())
192192
enum = AttrRW(Enum(enum.IntEnum("Enum", {"RED": 0, "GREEN": 1, "BLUE": 2})))
193193
one_d_waveform = AttrRW(Waveform(np.int32, (10,)))

tests/transport/graphQL/test_graphQL.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
AssertableControllerAPI,
1010
MyTestController,
1111
TestHandler,
12-
TestSender,
12+
TestSetter,
1313
TestUpdater,
1414
)
1515

@@ -23,7 +23,7 @@ class GraphQLController(MyTestController):
2323
read_write_int = AttrRW(Int(), handler=TestHandler())
2424
read_write_float = AttrRW(Float())
2525
read_bool = AttrR(Bool())
26-
write_bool = AttrW(Bool(), handler=TestSender())
26+
write_bool = AttrW(Bool(), handler=TestSetter())
2727
read_string = AttrRW(String())
2828

2929

tests/transport/rest/test_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
AssertableControllerAPI,
99
MyTestController,
1010
TestHandler,
11-
TestSender,
11+
TestSetter,
1212
TestUpdater,
1313
)
1414

@@ -23,7 +23,7 @@ class RestController(MyTestController):
2323
read_write_int = AttrRW(Int(), handler=TestHandler())
2424
read_write_float = AttrRW(Float())
2525
read_bool = AttrR(Bool())
26-
write_bool = AttrW(Bool(), handler=TestSender())
26+
write_bool = AttrW(Bool(), handler=TestSetter())
2727
read_string = AttrRW(String())
2828
enum = AttrRW(Enum(enum.IntEnum("Enum", {"RED": 0, "GREEN": 1, "BLUE": 2})))
2929
one_d_waveform = AttrRW(Waveform(np.int32, (10,)))

tests/transport/tango/test_dsr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
AssertableControllerAPI,
1111
MyTestController,
1212
TestHandler,
13-
TestSender,
13+
TestSetter,
1414
TestUpdater,
1515
)
1616

@@ -37,7 +37,7 @@ class TangoController(MyTestController):
3737
read_write_int = AttrRW(Int(), handler=TestHandler())
3838
read_write_float = AttrRW(Float())
3939
read_bool = AttrR(Bool())
40-
write_bool = AttrW(Bool(), handler=TestSender())
40+
write_bool = AttrW(Bool(), handler=TestSetter())
4141
read_string = AttrRW(String())
4242
enum = AttrRW(Enum(enum.IntEnum("Enum", {"RED": 0, "GREEN": 1, "BLUE": 2})))
4343
one_d_waveform = AttrRW(Waveform(np.int32, (10,)))

0 commit comments

Comments
 (0)