diff --git a/CHANGELOG.md b/CHANGELOG.md index 96a1b1f62..573189437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added Shift+scroll wheel and ctrl+scroll wheel to scroll horizontally - Added `Tree.action_toggle_node` to toggle a node without selecting, and bound it to Space https://github.com/Textualize/textual/issues/1433 - Added `Tree.reset` to fully reset a `Tree` https://github.com/Textualize/textual/issues/1437 -- Added DOMNode.watch method https://github.com/Textualize/textual/pull/1750 +- Added DOMNode.watch method https://github.com/Textualize/textual/pull/1750 ### Changed @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Removed - Methods `MessagePump.emit` and `MessagePump.emit_no_wait` https://github.com/Textualize/textual/pull/1738 +- Removed `reactive.watch` in favor of DOMNode.watch. ## [0.10.1] - 2023-01-20 diff --git a/src/textual/dom.py b/src/textual/dom.py index 97034a56f..07f994958 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -4,7 +4,6 @@ import re from inspect import getfile from typing import ( TYPE_CHECKING, - Callable, ClassVar, Iterable, Iterator, @@ -23,6 +22,7 @@ from rich.tree import Tree from ._context import NoActiveAppError from ._node_list import NodeList +from ._types import CallbackType from .binding import Bindings, BindingType from .color import BLACK, WHITE, Color from .css._error_tools import friendly_list @@ -649,7 +649,11 @@ class DOMNode(MessagePump): return [child for child in self.children if child.display] def watch( - self, obj: DOMNode, attribute_name: str, callback: Callable, init: bool = True + self, + obj: DOMNode, + attribute_name: str, + callback: CallbackType, + init: bool = True, ) -> None: """Watches for modifications to reactive attributes on another object. diff --git a/src/textual/reactive.py b/src/textual/reactive.py index cd891ffec..58f9a0837 100644 --- a/src/textual/reactive.py +++ b/src/textual/reactive.py @@ -17,7 +17,7 @@ import rich.repr from . import events from ._callback import count_parameters -from ._types import MessageTarget +from ._types import MessageTarget, CallbackType if TYPE_CHECKING: from .dom import DOMNode @@ -329,7 +329,7 @@ def _watch( node: DOMNode, obj: Reactable, attribute_name: str, - callback: Callable[[Any], object], + callback: CallbackType, *, init: bool = True, ) -> None: