diff --git a/Orange/widgets/utils/itemmodels.py b/Orange/widgets/utils/itemmodels.py index 9d15f776f71..3bae2370cc9 100644 --- a/Orange/widgets/utils/itemmodels.py +++ b/Orange/widgets/utils/itemmodels.py @@ -107,7 +107,9 @@ def __init__(self, sequence=None, parent=None, editable=False): self._editable = editable self._table = None self._roleData = {} - self.wrap(sequence or []) + if sequence is None: + sequence = [] + self.wrap(sequence) def rowCount(self, parent=QModelIndex()): return 0 if parent.isValid() else self._rows diff --git a/Orange/widgets/utils/tests/test_itemmodels.py b/Orange/widgets/utils/tests/test_itemmodels.py index b716fe402e6..7e9b6b6ef1f 100644 --- a/Orange/widgets/utils/tests/test_itemmodels.py +++ b/Orange/widgets/utils/tests/test_itemmodels.py @@ -42,6 +42,14 @@ def test_init(self): self.model = PyTableModel() self.assertEqual(self.model.rowCount(), 0) + def test_init_wrap_empty(self): + # pylint: disable=protected-access + t = [] + model = PyTableModel(t) + self.assertIs(model._table, t) + t.append([1, 2, 3]) + self.assertEqual(list(model), [[1, 2, 3]]) + def test_rowCount(self): self.assertEqual(self.model.rowCount(), 2) self.assertEqual(len(self.model), 2)