Skip to content

Commit 4bd60c7

Browse files
committed
fix test
1 parent 7391c05 commit 4bd60c7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/magicgui/widgets/bases/_container_widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __len__(self) -> int:
112112

113113
def __getattr__(self, name: str) -> WidgetVar:
114114
"""Return attribute ``name``. Will return a widget if present."""
115-
if wdg := self.get_widget(name):
115+
if (wdg := self._wdg_list.get_by_name(name)) is not None:
116116
return wdg
117117
return object.__getattribute__(self, name) # type: ignore
118118

@@ -443,7 +443,7 @@ def update(
443443
with self.changed.blocked():
444444
items = mapping.items() if isinstance(mapping, Mapping) else mapping
445445
for key, value in chain(items, kwargs.items()):
446-
if isinstance(wdg := self.get_widget(key), BaseValueWidget):
446+
if isinstance(wdg := self._wdg_list.get_by_name(key), BaseValueWidget):
447447
wdg.value = value
448448
self.changed.emit(self)
449449

src/magicgui/widgets/bases/_named_list.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from collections.abc import Iterator, MutableSequence
2-
from typing import TYPE_CHECKING, Generic, Optional, TypeVar, overload
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Generic, TypeVar, overload
34

45
if TYPE_CHECKING:
6+
from collections.abc import Iterator, MutableSequence
57
from typing import Protocol
68

79
class Named(Protocol):
@@ -37,7 +39,7 @@ def append(self, item: T) -> None:
3739
"""Appends an item at the end of the list."""
3840
self.insert(len(self._list), item)
3941

40-
def get_by_name(self, name: str) -> Optional[T]:
42+
def get_by_name(self, name: str) -> T | None:
4143
"""Returns the item with the given name, or None if not found."""
4244
return self._dict.get(name)
4345

@@ -72,3 +74,6 @@ def __len__(self) -> int:
7274

7375
def __iter__(self) -> Iterator[T]:
7476
return iter(self._list)
77+
78+
def __repr__(self):
79+
return repr(self._list)

0 commit comments

Comments
 (0)