Skip to content

Commit

Permalink
chore: Merge branch 'main' into unify-pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Feb 24, 2024
2 parents 80186dc + 9f75e18 commit b589b42
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/psygnal/_evented_model_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from types import TracebackType

import pydantic.version

if pydantic.version.VERSION.startswith("2"):
from ._evented_model_v2 import EventedModel as EventedModelV1
else:
from ._evented_model_v1 import EventedModel as EventedModelV2


class ComparisonDelayer:
def __init__(self, target: EventedModelV1 | EventedModelV2) -> None:
self._target = target

def __enter__(self) -> None:
self._target._delay_check_semaphore += 1

def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
self._target._delay_check_semaphore -= 1
self._target._check_if_values_changed_and_emit_if_needed()
2 changes: 1 addition & 1 deletion tests/test_evented_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ class Model(EventedModel):
mock1.assert_called_once()


def test_if_event_is_emited_only_once():
def test_if_event_is_emitted_only_once() -> None:
"""Check if, for complex property setters, the event is emitted only once."""

class SampleClass(EventedModel):
Expand Down

0 comments on commit b589b42

Please sign in to comment.