mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into overall-important
This commit is contained in:
2
.github/workflows/pythonpackage.yml
vendored
2
.github/workflows/pythonpackage.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
- name: Install and configure Poetry
|
||||
uses: snok/install-poetry@v1.3.3
|
||||
with:
|
||||
version: 1.2.2
|
||||
version: 1.4.2
|
||||
virtualenvs-in-project: true
|
||||
- name: Install dependencies
|
||||
run: poetry install --extras "dev"
|
||||
|
||||
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Fixed `!important` not applying to `outline` https://github.com/Textualize/textual/issues/2420
|
||||
- Fixed `outline-right` not being recognised https://github.com/Textualize/textual/issues/2446
|
||||
|
||||
### Added
|
||||
|
||||
- Watch methods can now optionally be private https://github.com/Textualize/textual/issues/2382
|
||||
|
||||
## [0.22.3] - 2023-04-29
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -241,9 +241,13 @@ class Reactive(Generic[ReactiveType]):
|
||||
events.Callback(callback=partial(await_watcher, watch_result))
|
||||
)
|
||||
|
||||
watch_function = getattr(obj, f"watch_{name}", None)
|
||||
if callable(watch_function):
|
||||
invoke_watcher(watch_function, old_value, value)
|
||||
private_watch_function = getattr(obj, f"_watch_{name}", None)
|
||||
if callable(private_watch_function):
|
||||
invoke_watcher(private_watch_function, old_value, value)
|
||||
|
||||
public_watch_function = getattr(obj, f"watch_{name}", None)
|
||||
if callable(public_watch_function):
|
||||
invoke_watcher(public_watch_function, old_value, value)
|
||||
|
||||
# Process "global" watchers
|
||||
watchers: list[tuple[Reactable, Callable]]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
@@ -386,3 +388,25 @@ async def test_watch_compute():
|
||||
assert app.show_ac is False
|
||||
|
||||
assert watch_called == [True, True, False, False, True, True, False, False]
|
||||
|
||||
|
||||
async def test_public_and_private_watch() -> None:
|
||||
"""If a reactive/var has public and private watches both should get called."""
|
||||
|
||||
calls: dict[str, bool] = {"private": False, "public": False}
|
||||
|
||||
class PrivateWatchTest(App):
|
||||
counter = var(0, init=False)
|
||||
|
||||
def watch_counter(self) -> None:
|
||||
calls["public"] = True
|
||||
|
||||
def _watch_counter(self) -> None:
|
||||
calls["private"] = True
|
||||
|
||||
async with PrivateWatchTest().run_test() as pilot:
|
||||
assert calls["private"] is False
|
||||
assert calls["public"] is False
|
||||
pilot.app.counter += 1
|
||||
assert calls["private"] is True
|
||||
assert calls["public"] is True
|
||||
|
||||
Reference in New Issue
Block a user