textual icon indicating copy to clipboard operation
textual copied to clipboard

fix: add set_options to SelectionList

Open NSPC911 opened this issue 1 month ago • 4 comments

threw me off when this happened to rovr, because the self._selected never got cleared when set_options was used instead of clear_options + add_options

Please review the following checklist.

  • [x] Docstrings on all new or modified functions / classes
  • [ ] Updated documentation
  • [ ] Updated CHANGELOG.md (where appropriate)

NSPC911 avatar Nov 11 '25 15:11 NSPC911

Are you sure this is correct? You can build a SelectionList with tuples or Selection objects, but here it looks like you're trying to use SelectionType?

not really sure which one to use, given that OptionList's set_option method only takes in an Iterable OptionListContent

NSPC911 avatar Nov 11 '25 23:11 NSPC911

I'm confused, Did you check your code actually worked, or just throw the PR over the wall?

TomJGooding avatar Nov 12 '25 03:11 TomJGooding

The general code worked, but I'm not sure about which class to use as the type hint for the function

NSPC911 avatar Nov 12 '25 03:11 NSPC911

Sorry, I think I understand the problem now.

I thought the signature would just be similar to the SelectionList.add_options method:

https://github.com/Textualize/textual/blob/422852a1b74f97fa7770afedd8ae917cb0bde66c/src/textual/widgets/_selection_list.py#L629-L637

But of course this doesn't satisfy mypy and friends for super().set_options(options).

I realise now that I overlooked that this actually ends up calling SelectionList.add_options. Repeating the same runtime checks in both set_option and add_options would definitely be "sort of sub-optimal"!

TomJGooding avatar Nov 20 '25 19:11 TomJGooding