Skip to content

Commit def421f

Browse files
authored
Merge pull request #4546 from Textualize/action-target
fix for action targets
2 parents befacc1 + ee7416b commit def421f

6 files changed

Lines changed: 38 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.63.2] - 2024-05-23
9+
10+
### Fixed
11+
12+
- Fixed issue with namespaces in links https://github.com/Textualize/textual/pull/4546
13+
814
## [0.63.1] - 2024-05-22
915

1016
### Fixed
@@ -1996,6 +2002,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
19962002
- New handler system for messages that doesn't require inheritance
19972003
- Improved traceback handling
19982004

2005+
[0.63.2]: https://github.com/Textualize/textual/compare/v0.63.1...v0.63.2
19992006
[0.63.1]: https://github.com/Textualize/textual/compare/v0.63.0...v0.63.1
20002007
[0.63.0]: https://github.com/Textualize/textual/compare/v0.62.0...v0.63.0
20012008
[0.62.0]: https://github.com/Textualize/textual/compare/v0.61.1...v0.62.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "0.63.1"
3+
version = "0.63.2"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/app.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,7 +3038,7 @@ async def on_event(self, event: events.Event) -> None:
30383038
await super().on_event(event)
30393039

30403040
def _parse_action(
3041-
self, action: str, default_namespace: DOMNode
3041+
self, action: str | ActionParseResult, default_namespace: DOMNode
30423042
) -> tuple[DOMNode, str, tuple[object, ...]]:
30433043
"""Parse an action.
30443044
@@ -3051,7 +3051,11 @@ def _parse_action(
30513051
Returns:
30523052
A tuple of (node or None, action name, tuple of parameters).
30533053
"""
3054-
destination, action_name, params = actions.parse(action)
3054+
if isinstance(action, tuple):
3055+
destination, action_name, params = action
3056+
else:
3057+
destination, action_name, params = actions.parse(action)
3058+
30553059
action_target: DOMNode | None = None
30563060
if destination:
30573061
if destination not in self._action_targets:
@@ -3098,14 +3102,9 @@ async def run_action(
30983102
Returns:
30993103
True if the event has been handled.
31003104
"""
3101-
if isinstance(action, str):
3102-
action_target, action_name, params = self._parse_action(
3103-
action, self if default_namespace is None else default_namespace
3104-
)
3105-
else:
3106-
# assert isinstance(action, tuple)
3107-
_, action_name, params = action
3108-
action_target = self
3105+
action_target, action_name, params = self._parse_action(
3106+
action, self if default_namespace is None else default_namespace
3107+
)
31093108

31103109
if action_target.check_action(action_name, params):
31113110
return await self._dispatch_action(action_target, action_name, params)

tests/test_data_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ def compose(self) -> ComposeResult:
14381438

14391439
def on_mount(self) -> None:
14401440
table = self.query_one(DataTable)
1441-
table.border_title = "[@click=test_link]Border Link[/]"
1441+
table.border_title = "[@click=app.test_link]Border Link[/]"
14421442

14431443
def action_test_link(self) -> None:
14441444
self.link_clicked = True

tests/test_issue_4248.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ async def test_issue_4248() -> None:
1010
bumps = 0
1111

1212
class ActionApp(App[None]):
13-
1413
def compose(self) -> ComposeResult:
1514
yield Label("[@click]click me and crash[/]", id="nothing")
1615
yield Label("[@click=]click me and crash[/]", id="no-params")
1716
yield Label("[@click=()]click me and crash[/]", id="empty-params")
1817
yield Label("[@click=foobar]click me[/]", id="unknown-sans-parens")
1918
yield Label("[@click=foobar()]click me[/]", id="unknown-with-parens")
20-
yield Label("[@click=bump]click me[/]", id="known-sans-parens")
21-
yield Label("[@click=bump()]click me[/]", id="known-empty-parens")
22-
yield Label("[@click=bump(100)]click me[/]", id="known-with-param")
19+
yield Label("[@click=app.bump]click me[/]", id="known-sans-parens")
20+
yield Label("[@click=app.bump()]click me[/]", id="known-empty-parens")
21+
yield Label("[@click=app.bump(100)]click me[/]", id="known-with-param")
2322

2423
def action_bump(self, by_value: int = 1) -> None:
2524
nonlocal bumps

tests/test_links.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@
33
from textual.widgets import Label
44

55

6-
async def test_links():
6+
async def test_links() -> None:
77
"""Regression test for https://github.com/Textualize/textual/issues/4536"""
88
messages: list[str] = []
99

10+
class LinkLabel(Label):
11+
def action_bell_message(self, message: str) -> None:
12+
nonlocal messages
13+
messages.append(f"label {message}")
14+
1015
class HomeScreen(Screen[None]):
1116
def compose(self) -> ComposeResult:
12-
yield Label("[@click=app.bell_message('hi')]Ring the bell![/]")
17+
yield LinkLabel("[@click=app.bell_message('foo')]Ring the bell![/]")
18+
yield LinkLabel("[@click=screen.bell_message('bar')]Ring the bell![/]")
19+
yield LinkLabel("[@click=bell_message('baz')]Ring the bell![/]")
20+
21+
def action_bell_message(self, message: str) -> None:
22+
nonlocal messages
23+
messages.append(f"screen {message}")
1324

1425
class ScreenNamespace(App[None]):
1526
def get_default_screen(self) -> HomeScreen:
1627
return HomeScreen()
1728

1829
def action_bell_message(self, message: str) -> None:
1930
nonlocal messages
20-
messages.append(message)
31+
messages.append(f"app {message}")
2132

2233
async with ScreenNamespace().run_test() as pilot:
2334
await pilot.click(offset=(5, 0))
24-
assert messages == ["hi"]
35+
await pilot.click(offset=(5, 1))
36+
await pilot.click(offset=(5, 2))
37+
assert messages == ["app foo", "screen bar", "label baz"]

0 commit comments

Comments
 (0)