From 1f75ea0e85c03885af21d638462c99888e33aa9a Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Tue, 22 Oct 2024 08:28:43 +0000 Subject: [PATCH] Address PR comments --- src/ophyd_async/core/_device.py | 8 +++++++- src/ophyd_async/core/_signal.py | 6 +++++- src/ophyd_async/core/_soft_signal_backend.py | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ophyd_async/core/_device.py b/src/ophyd_async/core/_device.py index ce0b92fd25..883cf8ebf6 100644 --- a/src/ophyd_async/core/_device.py +++ b/src/ophyd_async/core/_device.py @@ -84,7 +84,13 @@ def set_name(self, name: str): _setup_child(self, child_name, child) def __setattr__(self, name: str, value: Any) -> None: - if name != "parent" and isinstance(value, Device): + if name == "parent": + if self.parent not in (value, None): + raise TypeError( + f"Cannot set the parent of {self} to be {value}: " + f"it is already a child of {self.parent}" + ) + elif isinstance(value, Device): _setup_child(self, name, value) return super().__setattr__(name, value) diff --git a/src/ophyd_async/core/_signal.py b/src/ophyd_async/core/_signal.py index 91b62b69b2..a4562c375d 100644 --- a/src/ophyd_async/core/_signal.py +++ b/src/ophyd_async/core/_signal.py @@ -128,7 +128,11 @@ def _callback(self, reading: Reading[SignalDatatypeT]): for function, want_value in self._listeners.items(): self._notify(function, want_value) - def _notify(self, function: Callback, want_value: bool): + def _notify( + self, + function: Callback[dict[str, Reading[SignalDatatypeT]] | SignalDatatypeT], + want_value: bool, + ): assert self._reading, "Monitor not working" if want_value: function(self._reading["value"]) diff --git a/src/ophyd_async/core/_soft_signal_backend.py b/src/ophyd_async/core/_soft_signal_backend.py index 70b2f676e1..6b4719a10c 100644 --- a/src/ophyd_async/core/_soft_signal_backend.py +++ b/src/ophyd_async/core/_soft_signal_backend.py @@ -27,6 +27,9 @@ class SoftConverter(Generic[SignalDatatypeT]): + # This is Any -> SignalDatatypeT because we support coercing + # value types to SignalDatatype to allow people to do things like + # SignalRW[Enum].set("enum value") @abstractmethod def write_value(self, value: Any) -> SignalDatatypeT: ...