You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ListView.pop(index) can remove an item from a nested list instead of its own child #6804
ListView.pop(index) counts direct children for its index handling, but looks up the item with self.query("ListItem")[index], which also includes nested list items. With a nested ListView in the first item, outer.pop(1) removes the inner item instead of the outer list's second item.
Reproduced on current main (5e5b7ef58b8c5572c13a3ff9027d756623661495), Textual 8.2.8, Rich 15.0.0, Python 3.14.7, macOS. I checked open and closed issues and PRs; I couldn't find a report for this nested-item deletion. Textual 8.2.8 is also the current PyPI release.
direct children before: ['first', 'second']
all items before: ['first', 'inner-item', 'second']
direct children after pop(1): ['first', 'second']
all items after: ['first', 'second']
Expected: the direct children become ['first'], and inner-item stays inside the first item's nested list. The current behavior deletes data from the wrong list while leaving the requested item in place.
I can reproduce this on main. remove_items has the same problem: it also indexes self.query("ListItem"), so remove_items([1]) on the example removes inner-item too.
Proposed fix: index the list's direct children instead of a query, i.e. self._nodes[index] in pop and items = self._nodes in remove_items. A ListView's children are its ListItems, and the index bookkeeping in both methods already counts self._nodes, so the lookup and the index update would agree. I have this ready with two regression tests (nested ListView in the first item; pop(1), pop() and remove_items([1, -1]) remove only the outer items and keep inner-item), which fail on main and pass with the change; tests/listview passes.
@willmcgugan, would you like a PR for this? Per the AI policy: it would be AI-assisted (Claude Code, Opus 5.5), with the template filled in.
remove_items() has the same problem, since it also uses self.query("ListItem"):
python
await outer.remove_items([1])
# expected: outer children ['first'], inner-item kept
# actual: 'inner-item' removed from the nested list, 'second' still there
I tried this locally: pop(1), pop(), pop(-2) and remove_items([1]) all remove the correct direct child and leave the nested list untouched, and the existing tests in tests/listview pass.
@willmcgugan would you be okay with me opening a PR with this fix and regression tests for both pop() and remove_items()?
Activity
github-actions commentedon Nov 29, 2026
We found the following entries in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.
This project is developed and maintained by Will McGugan. Consider sponsoring Will's work on this project (and others).
This is an automated reply, generated by FAQtory
Harp404 commentedon Nov 30, 2026
I can reproduce this on
main.remove_itemshas the same problem: it also indexesself.query("ListItem"), soremove_items([1])on the example removesinner-itemtoo.Proposed fix: index the list's direct children instead of a query, i.e.
self._nodes[index]inpopanditems = self._nodesinremove_items. AListView's children are itsListItems, and the index bookkeeping in both methods already countsself._nodes, so the lookup and the index update would agree. I have this ready with two regression tests (nestedListViewin the first item;pop(1),pop()andremove_items([1, -1])remove only the outer items and keepinner-item), which fail onmainand pass with the change;tests/listviewpasses.@willmcgugan, would you like a PR for this? Per the AI policy: it would be AI-assisted (Claude Code, Opus 5.5), with the template filled in.
OmDhamal-08 commentedon Nov 30, 2026
I can reproduce this on current main (5e5b7ef).
@BichengWang
remove_items() has the same problem, since it also uses self.query("ListItem"):
I tried this locally: pop(1), pop(), pop(-2) and remove_items([1]) all remove the correct direct child and leave the nested list untouched, and the existing tests in tests/listview pass.
@willmcgugan would you be okay with me opening a PR with this fix and regression tests for both pop() and remove_items()?