From 906af24d2492e6eb87c741e5541d5276ace9a9b3 Mon Sep 17 00:00:00 2001 From: Jasmijn Wellner Date: Sun, 5 Oct 2025 17:48:44 +0200 Subject: [PATCH 1/3] Add tests for str() + Content() fix --- tests/test_content.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_content.py b/tests/test_content.py index 5020db8f90..70e30db56a 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -136,6 +136,14 @@ def test_add() -> None: assert content.spans == [Span(0, 3, "red"), Span(4, 7, "blue")] assert content.cell_length == 7 +def test_radd() -> NOne + """Test reverse addition.""" + assert "foo" + Content("bar") == Content("foobar") + + # Test spans after addition + content = "foo " + Content.styled("bar", "blue") + assert str(content) == "foo bar" + assert content.spans == [Span(4, 7, "blue")] def test_from_markup(): """Test simple parsing of content markup.""" From a00fdeba448023664813c5fce22d52ec8637ded7 Mon Sep 17 00:00:00 2001 From: Jasmijn Wellner Date: Sun, 5 Oct 2025 17:51:02 +0200 Subject: [PATCH 2/3] Fix str() + Content() --- src/textual/content.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/textual/content.py b/src/textual/content.py index 8c65440c06..b860bca845 100644 --- a/src/textual/content.py +++ b/src/textual/content.py @@ -760,10 +760,10 @@ def __add__(self, other: Content | str) -> Content: return content return NotImplemented - def __radd__(self, other: Content | str) -> Content: - if not isinstance(other, (Content, str)): + def __radd__(self, other: str) -> Content: + if not isinstance(other, str): return NotImplemented - return self + other + return Content(other) + self @classmethod def _trim_spans(cls, text: str, spans: list[Span]) -> list[Span]: From ceac08493b39fd3725249695d955521e284f2ac2 Mon Sep 17 00:00:00 2001 From: Jasmijn Wellner Date: Sun, 5 Oct 2025 18:07:14 +0200 Subject: [PATCH 3/3] Fix typo --- tests/test_content.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_content.py b/tests/test_content.py index 70e30db56a..61e86d0f68 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -136,7 +136,7 @@ def test_add() -> None: assert content.spans == [Span(0, 3, "red"), Span(4, 7, "blue")] assert content.cell_length == 7 -def test_radd() -> NOne +def test_radd() -> None: """Test reverse addition.""" assert "foo" + Content("bar") == Content("foobar")