From 643c2d933b0451c7ebe6fef065393762ec2d8546 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:10:56 +0100 Subject: [PATCH] ensure pop error is original index rather than normalized --- src/textual/widgets/_list_view.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/textual/widgets/_list_view.py b/src/textual/widgets/_list_view.py index c452ef4a79..d4783dd074 100644 --- a/src/textual/widgets/_list_view.py +++ b/src/textual/widgets/_list_view.py @@ -247,16 +247,15 @@ def pop(self, index: Optional[int] = None) -> AwaitComplete: raise IndexError("pop from empty list") index = index if index is not None else -1 - if index < 0: - index += len(self) item_to_remove = self.query("ListItem")[index] + normalized_index = index if index >= 0 else index + len(self) async def do_pop(): await item_to_remove.remove() if self.index is not None: - if index == self.index: + if normalized_index == self.index: self.index = self.index - elif index < self.index: + elif normalized_index < self.index: self.index = self.index - 1 return AwaitComplete(do_pop())