From a811b9cccff0af3602d610ffa2e7458cd27f178f Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Wed, 19 Mar 2014 14:32:09 +0100 Subject: [PATCH] remove more mutable default arguments --- sloth/annotations/model.py | 13 ++++++++----- sloth/gui/buttonarea.py | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index 8feaec4..291e3e3 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -286,11 +286,13 @@ class RootModelItem(ModelItem): if hasattr(child, 'getAnnotations')] class KeyValueModelItem(ModelItem, MutableMapping): - def __init__(self, hidden=[], properties=None): + def __init__(self, hidden=None, properties=None): ModelItem.__init__(self) - self._dict = {} - self._items = {} - self._hidden = hidden + [None, 'class', 'unlabeled', 'unconfirmed'] + self._dict = {} + self._items = {} + self._hidden = set(hidden or []) + self._hidden.update({None, 'class', 'unlabeled', 'unconfirmed'}) + # dummy key/value so that pyqt does not convert the dict # into a QVariantMap while communicating with the Views self._dict[None] = None @@ -396,7 +398,8 @@ class KeyValueModelItem(ModelItem, MutableMapping): self._emitDataChanged('unconfirmed') class FileModelItem(KeyValueModelItem): - def __init__(self, fileinfo, hidden=['filename']): + def __init__(self, fileinfo, hidden=None): + if not hidden: hidden = ['filename'] KeyValueModelItem.__init__(self, hidden=hidden, properties=fileinfo) def data(self, role=Qt.DisplayRole, column=0): diff --git a/sloth/gui/buttonarea.py b/sloth/gui/buttonarea.py index 2dd8181..029869a 100644 --- a/sloth/gui/buttonarea.py +++ b/sloth/gui/buttonarea.py @@ -141,9 +141,9 @@ class ButtonArea(QWidget): else: button_list.hide() - def add_label(self, label_name, properties = {}): + def add_label(self, label_name, properties=None): self.label_names.append(label_name) - self.label_properties[label_name] = properties + self.label_properties[label_name] = properties or {} for key, value in properties.items(): if key in self.properties: self.properties[key] = unique_list(self.properties[key] + value)