From a4f755b4f5ae8cea8e79a1db2a13b5673189f6c4 Mon Sep 17 00:00:00 2001 From: hanjinliu Date: Mon, 9 May 2022 23:10:56 +0900 Subject: [PATCH] fix ListEdit annotation check --- magicgui/widgets/_concrete.py | 3 ++- tests/test_widgets.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/magicgui/widgets/_concrete.py b/magicgui/widgets/_concrete.py index 78a469d29..f787e5396 100644 --- a/magicgui/widgets/_concrete.py +++ b/magicgui/widgets/_concrete.py @@ -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: diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 1bb80e800..81f7a80e7 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -862,6 +862,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."""