Skip to content

Commit

Permalink
Allow equality comparisons for signal (#524)
Browse files Browse the repository at this point in the history
* Allow equality comparisons for signal

These comparisons are needed by trigger_and_read for example.

* Entirely remove _fail() on comparisons
  • Loading branch information
Tom-Willemsen authored Aug 20, 2024
1 parent 9701810 commit 406ac08
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
15 changes: 0 additions & 15 deletions src/ophyd_async/core/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ async def wrapper(self: Signal, *args, **kwargs):
return wrapper


def _fail(self, other, *args, **kwargs):
if isinstance(other, Signal):
raise TypeError(
"Can't compare two Signals, did you mean await signal.get_value() instead?"
)
else:
return NotImplemented


class Signal(Device, Generic[T]):
"""A Device with the concept of a value, with R, RW, W and X flavours"""

Expand Down Expand Up @@ -118,12 +109,6 @@ def source(self) -> str:
"""Like ca://PV_PREFIX:SIGNAL, or "" if not set"""
return self._backend.source(self.name)

__lt__ = __le__ = __eq__ = __ge__ = __gt__ = __ne__ = _fail

def __hash__(self):
# Restore the default implementation so we can use in a set or dict
return hash(id(self))


class _SignalCache(Generic[T]):
def __init__(self, backend: SignalBackend[T], signal: Signal):
Expand Down
21 changes: 0 additions & 21 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import logging
import re
import time
from asyncio import Event
from unittest.mock import ANY
Expand Down Expand Up @@ -37,26 +36,6 @@
from ophyd_async.plan_stubs import ensure_connected


async def test_signals_equality_raises():
s1 = epics_signal_rw(int, "pva://pv1", name="signal")
s2 = epics_signal_rw(int, "pva://pv2", name="signal")
await s1.connect(mock=True)
await s2.connect(mock=True)

with pytest.raises(
TypeError,
match=re.escape(
"Can't compare two Signals, did you mean await signal.get_value() instead?"
),
):
s1 == s2
with pytest.raises(
TypeError,
match=re.escape("'>' not supported between instances of 'SignalRW' and 'int'"),
):
s1 > 4


async def test_signal_can_be_given_backend_on_connect():
sim_signal = SignalR()
backend = MockSignalBackend(int)
Expand Down

0 comments on commit 406ac08

Please sign in to comment.