diff --git a/src/psygnal/_group_descriptor.py b/src/psygnal/_group_descriptor.py index 7aac8a0d..46535585 100644 --- a/src/psygnal/_group_descriptor.py +++ b/src/psygnal/_group_descriptor.py @@ -155,7 +155,7 @@ def _build_dataclass_signal_group( else: eq_map[name] = _pick_equality_operator(type_) field_type = object if type_ is None else type_ - signals[name] = sig = Signal(field_type) + signals[name] = sig = Signal(field_type, field_type) # patch in our custom SignalInstance class with maxargs=1 on connect_setattr sig._signal_instance_class = _DataclassFieldSignalInstance @@ -204,7 +204,7 @@ def __enter__(self) -> None: def __exit__(self, *args: Any) -> None: new: Any = getattr(self.obj, self.field, _NULL) if not _check_field_equality(type(self.obj), self.field, self._prev, new): - self.signal.emit(new) + self.signal.emit(new, self._prev) SetAttr = Callable[[Any, str, Any], None] diff --git a/tests/test_bench.py b/tests/test_bench.py index ba669430..9306f503 100644 --- a/tests/test_bench.py +++ b/tests/test_bench.py @@ -24,6 +24,7 @@ "print", ] + # fmt: off class Emitter: one_int = Signal(int) @@ -221,6 +222,9 @@ def _doit() -> None: foo.e = (2, "hello") benchmark(_doit) - for newval, attr in zip([2, "hello", False, 2.0, (2, "hello")], "abcde"): - mock.assert_any_call(EmissionInfo(getattr(foo.events, attr), (newval,))) - assert getattr(foo, attr) == newval + for emitted, attr in zip( + [(2, 1), ("hello", "hi"), (False, True), (2.0, 1.0), ((2, "hello"), (1, "hi"))], + "abcde", + ): + mock.assert_any_call(EmissionInfo(getattr(foo.events, attr), emitted)) + assert getattr(foo, attr) == emitted[0] diff --git a/tests/test_evented_decorator.py b/tests/test_evented_decorator.py index 0b41420d..71b8d468 100644 --- a/tests/test_evented_decorator.py +++ b/tests/test_evented_decorator.py @@ -45,7 +45,7 @@ def _check_events(cls, events_ns="events"): assert obj.bar == 1 obj.bar = 2 assert obj.bar == 2 - mock.assert_called_once_with(2) + mock.assert_called_once_with(2, 1) mock.reset_mock() obj.baz = "3" diff --git a/tests/test_group_descriptor.py b/tests/test_group_descriptor.py index 808b86a0..ccf4ab39 100644 --- a/tests/test_group_descriptor.py +++ b/tests/test_group_descriptor.py @@ -126,7 +126,7 @@ class Foo: foo._events.a.connect(mock) foo.a = 2 if patch_setattr: - mock.assert_called_once_with(2) + mock.assert_called_once_with(2, 1) else: mock.assert_not_called() @@ -142,7 +142,8 @@ class Foo: @_group_descriptor.evented_setattr("_events") def __setattr__(self, __name: str, __value: Any) -> None: - mock1(__name, __value) + old = getattr(self, __name, None) + mock1(__name, __value, old) super().__setattr__(__name, __value) assert _group_descriptor.is_evented(Foo.__setattr__) @@ -154,8 +155,8 @@ def __setattr__(self, __name: str, __value: Any) -> None: mock = Mock() foo._events.a.connect(mock) foo.a = 2 - mock.assert_called_once_with(2) # confirm no double event emission - mock1.assert_called_with("a", 2) + mock.assert_called_once_with(2, 1) # confirm no double event emission + mock1.assert_called_with("a", 2, 1) def test_no_getattr_on_non_evented_fields() -> None: @@ -180,7 +181,7 @@ def b(self, value: int) -> None: foo = Foo(a=1) foo.events.a.connect(a_mock) foo.a = 2 - a_mock.assert_called_once_with(2) + a_mock.assert_called_once_with(2, 1) foo.b = 1 b_mock.assert_not_called() # getter shouldn't have been called