Skip to content

Commit 23b38e1

Browse files
committed
use first not last
1 parent 8deddf6 commit 23b38e1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/magicgui/widgets/bases/_named_list.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ def insert(self, index: int, item: T) -> None:
2828
2929
Raises ValueError if an item with the same name already exists.
3030
"""
31+
self._list.insert(index, item)
3132
# NB!
3233
# we don't actually assert name uniqueness here, because it ruins
33-
# the true list-like quality. So, when retrieving by name, you will
34-
# simply get the last item that has been inserted with that name.
35-
self._list.insert(index, item)
36-
self._dict[item.name] = item
34+
# the true list-like quality. So, when retrieving by name, you will
35+
# simply get the first item that has been inserted with that name.
36+
if item.name not in self._dict:
37+
self._dict[item.name] = item
3738

3839
def append(self, item: T) -> None:
3940
"""Appends an item at the end of the list."""

0 commit comments

Comments
 (0)