From 2594a49fbb74e33ef2eab40538b3230fae49ac47 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 22 Jul 2024 11:43:05 +0100 Subject: [PATCH 1/4] fix select --- src/textual/widgets/_select.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/textual/widgets/_select.py b/src/textual/widgets/_select.py index 6049dd3227..ef5be915c5 100644 --- a/src/textual/widgets/_select.py +++ b/src/textual/widgets/_select.py @@ -493,7 +493,10 @@ def _on_mount(self, _event: events.Mount) -> None: def _watch_expanded(self, expanded: bool) -> None: """Display or hide overlay.""" - overlay = self.query_one(SelectOverlay) + try: + overlay = self.query_one(SelectOverlay) + except NoMatches: + return self.set_class(expanded, "-expanded") if expanded: overlay.focus() From 97945522cbfa726eec672f9e2254902a77eb9c2e Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 22 Jul 2024 11:45:37 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 1 + tests/select/test_remove.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/select/test_remove.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef7ca7302..7245bc3a27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fixed issues in Kitty terminal after exiting app https://github.com/Textualize/textual/issues/4779 +- Fixed exception when removing Selects ## [0.73.0] - 2024-07-18 diff --git a/tests/select/test_remove.py b/tests/select/test_remove.py new file mode 100644 index 0000000000..989884a8c9 --- /dev/null +++ b/tests/select/test_remove.py @@ -0,0 +1,25 @@ +from textual.app import App, ComposeResult +from textual.widgets import Header, Select + +LINES = """I must not fear. +Fear is the mind-killer. +Fear is the little-death that brings total obliteration. +I will face my fear. +I will permit it to pass over me and through me.""".splitlines() + + +async def test_select_remove(): + # Regression test for https://github.com/Textualize/textual/issues/4782 + class SelectApp(App): + def compose(self) -> ComposeResult: + self.select = Select((line, line) for line in LINES) + self.select.watch_value = self.on_select + yield Header() + yield self.select + + def on_select(self): + self.select.remove() + + app = SelectApp() + async with app.run_test() as pilot: + await pilot.press("enter", "down", "down", "enter") From 63535c7f01b1e15ed9bc290286f71226d8020fba Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 22 Jul 2024 11:47:14 +0100 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7245bc3a27..500ccee7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fixed issues in Kitty terminal after exiting app https://github.com/Textualize/textual/issues/4779 -- Fixed exception when removing Selects +- Fixed exception when removing Selects https://github.com/Textualize/textual/pull/4786 ## [0.73.0] - 2024-07-18 From bcf20b68bdeaf29bd6b6566384f8ff806eae3cb5 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Mon, 22 Jul 2024 12:19:01 +0100 Subject: [PATCH 4/4] comment --- src/textual/widgets/_select.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/textual/widgets/_select.py b/src/textual/widgets/_select.py index ef5be915c5..12c6f05537 100644 --- a/src/textual/widgets/_select.py +++ b/src/textual/widgets/_select.py @@ -496,6 +496,7 @@ def _watch_expanded(self, expanded: bool) -> None: try: overlay = self.query_one(SelectOverlay) except NoMatches: + # The widget has likely been removed return self.set_class(expanded, "-expanded") if expanded: