Skip to content

Commit

Permalink
fix ListEdit annotation check (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed May 18, 2022
1 parent 30d78de commit 4ea93d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion magicgui/widgets/_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,9 @@ def __init__(
self.margins = (0, 0, 0, 0)

if not isinstance(value, _Unset):
# check type consistency
types = {type(a) for a in value}
if len(types) == 1:
if len(types) <= 1:
if self._args_type is None:
self._args_type = types.pop()
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,18 @@ def f3(x: List[int] = [0]):
assert f3.x[0].max == 10
assert f3.x[0].step == 5

@magicgui
def f4(x: List[int] = ()): # type: ignore
pass

assert type(f4.x) is widgets.ListEdit
assert f4.x.annotation == List[int]
assert f4.x._args_type is int
assert f4.x.value == []
f4.x.btn_plus.changed()
assert type(f4.x[0]) is widgets.SpinBox
assert f4.x.value == [0]


def test_tuple_edit():
"""Test TupleEdit."""
Expand Down

0 comments on commit 4ea93d7

Please sign in to comment.