Skip to content

Commit 48598a6

Browse files
authored
fix broken repr in file monitor (#2795)
* fix broken repr in file monitor * no need for callback * docstrings and typing
1 parent c966243 commit 48598a6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/textual/_callback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def _invoke(callback: Callable, *params: object) -> Any:
3737
return result
3838

3939

40-
async def invoke(callback: Callable, *params: object) -> Any:
40+
async def invoke(callback: Callable[[], Any], *params: object) -> Any:
4141
"""Invoke a callback with an arbitrary number of parameters.
4242
4343
Args:

src/textual/file_monitor.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ class FileMonitor:
1515

1616
_paths: set[Path]
1717

18-
def __init__(self, paths: Sequence[Path], callback: Callable) -> None:
18+
def __init__(self, paths: Sequence[Path], callback: Callable[[], None]) -> None:
19+
"""Monitor the given file paths for changes.
20+
21+
Args:
22+
paths: Paths to monitor.
23+
callback: Callback to invoke if any of the paths change.
24+
"""
1925
self._paths = set(paths)
2026
self.callback = callback
2127
self._modified = self._get_last_modified_time()
2228

29+
def __rich_repr__(self) -> rich.repr.Result:
30+
yield self._paths
31+
2332
def _get_last_modified_time(self) -> float:
2433
"""Get the most recent modified time out of all files being watched."""
2534
return max(os.stat(path).st_mtime for path in self._paths)

tests/test_file_monitor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pathlib import Path
2+
3+
from textual.file_monitor import FileMonitor
4+
5+
6+
def test_repr() -> None:
7+
file_monitor = FileMonitor([Path(".")], lambda: None)
8+
assert "FileMonitor" in repr(file_monitor)

0 commit comments

Comments
 (0)