Skip to content

Commit

Permalink
Merge pull request #4270 from tybug/db-fix
Browse files Browse the repository at this point in the history
Adjust db pubsub type hints and remove print
  • Loading branch information
tybug authored Feb 24, 2025
2 parents e75348d + 5622df5 commit 3453f36
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RELEASE_TYPE: patch

Adjust type hints for the pub-sub database implementation in :ref:`version 6.126.0 <v6.126.0>`, and remove a remnant debug print in its implementation.
13 changes: 5 additions & 8 deletions hypothesis-python/src/hypothesis/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
from watchdog.observers.api import BaseObserver

StrPathT: "TypeAlias" = Union[str, PathLike[str]]
ListenerEventType: "TypeAlias" = Literal["save", "delete"]
SaveDataT: "TypeAlias" = tuple[bytes, bytes] # key, value
DeleteDataT: "TypeAlias" = tuple[bytes, Optional[bytes]] # key, value
MoveDataT: "TypeAlias" = tuple[bytes, bytes, bytes] # src, dest, value
ListenerDataT: "TypeAlias" = Union[SaveDataT, DeleteDataT, MoveDataT]
ListenerT: "TypeAlias" = Callable[[tuple[ListenerEventType, ListenerDataT]], Any]
ListenerEventT: "TypeAlias" = Union[
tuple[Literal["save"], SaveDataT], tuple[Literal["delete"], DeleteDataT]
]
ListenerT: "TypeAlias" = Callable[[ListenerEventT], Any]


def _usable_dir(path: StrPathT) -> bool:
Expand Down Expand Up @@ -204,7 +204,7 @@ def clear_listeners(self) -> None:
if had_listeners:
self._stop_listening()

def _broadcast_change(self, event: tuple[ListenerEventType, ListenerDataT]) -> None:
def _broadcast_change(self, event: ListenerEventT) -> None:
"""
Called when a value has been either added to or deleted from a key in
the underlying database store. event_type is one of "save" or "delete".
Expand Down Expand Up @@ -440,7 +440,6 @@ class Handler(FileSystemEventHandler):
def on_created(
_self, event: Union[FileCreatedEvent, DirCreatedEvent]
) -> None:
print("create", event)
# we only registered for the file creation event
assert not isinstance(event, DirCreatedEvent)
# watchdog events are only bytes if we passed a byte path to
Expand Down Expand Up @@ -471,7 +470,6 @@ def on_created(
def on_deleted(
self, event: Union[FileDeletedEvent, DirDeletedEvent]
) -> None:
print("delete", event)
assert not isinstance(event, DirDeletedEvent)
assert isinstance(event.src_path, str)

Expand All @@ -483,7 +481,6 @@ def on_deleted(
_broadcast_change(("delete", (key, None)))

def on_moved(self, event: Union[FileMovedEvent, DirMovedEvent]) -> None:
print("move", event)
assert not isinstance(event, DirMovedEvent)
assert isinstance(event.src_path, str)
assert isinstance(event.dest_path, str)
Expand Down
4 changes: 4 additions & 0 deletions hypothesis-python/tests/watchdog/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import time
from collections import Counter

import pytest

from hypothesis import Phase, settings
from hypothesis.database import (
DirectoryBasedExampleDatabase,
Expand Down Expand Up @@ -77,6 +79,8 @@ def listener(event):
}


# TODO flaky failure on linux
@pytest.mark.xfail(strict=False)
def test_database_listener_directory_explicit(tmp_path):
db = DirectoryBasedExampleDatabase(tmp_path)
events = []
Expand Down

0 comments on commit 3453f36

Please sign in to comment.