Skip to content

Commit b04b4cc

Browse files
authored
Merge pull request #5650 from Zaloog/lg/fix-select-selection
Bugfix Select.selection with no value selected
2 parents e27bcda + 4d5b346 commit b04b4cc

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2222
- Static and Label now accept Content objects, satisfying type checkers https://github.com/Textualize/textual/pull/5618
2323
- Fixed click selection not being disabled when allow_select was set to false https://github.com/Textualize/textual/issues/5627
2424
- Fixed crash on clicking line API border https://github.com/Textualize/textual/pull/5641
25+
- Fixed Select.selection now correctly returns None if Select.BLANK is selected instead of an AssertionError
2526
- Fixed additional spaces after text-wrapping https://github.com/Textualize/textual/pull/5657
2627
- Added missing `scroll_end` parameter to the `Log.write_line` method https://github.com/Textualize/textual/pull/5672
2728
- Restored support for blink https://github.com/Textualize/textual/pull/5675

src/textual/widgets/_select.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ def selection(self) -> SelectType | None:
477477

478478
"""
479479
value = self.value
480-
assert not isinstance(value, NoSelection)
480+
if isinstance(value, NoSelection):
481+
return None
481482
return value
482483

483484
def _setup_variables_for_options(

tests/select/test_blank_and_clear.py

+10
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,13 @@ def compose(self):
6363
assert not select.is_blank()
6464
with pytest.raises(InvalidSelectValueError):
6565
select.clear()
66+
67+
async def test_selection_is_none_with_blank():
68+
class SelectApp(App[None]):
69+
def compose(self):
70+
yield Select(SELECT_OPTIONS)
71+
72+
app = SelectApp()
73+
async with app.run_test():
74+
select = app.query_one(Select)
75+
assert select.selection is None

0 commit comments

Comments
 (0)