<p>fixeria has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23513">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pySim/filesystem: fix mutable default list/dict arguments<br><br>Having lists and dictionaries as default argument values is a bad<br>idea, because the same instance of list/dict will be used by all<br>objects instanuated using such constructor:<br><br>  def appendItem(itemName, itemList=[]):<br>      itemList.append(itemName)<br>      return itemList<br><br>  print(appendItem('notebook'))<br>  print(appendItem('pencil'))<br>  print(appendItem('eraser'))<br><br>Output:<br><br>  ['notebook']<br>  ['notebook', 'pencil']<br>  ['notebook', 'pencil', 'eraser']<br><br>Change-Id: I83d718ff9c3ff6aef47930f38d7f50424f9b880f<br>---<br>M pySim/filesystem.py<br>1 file changed, 8 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/13/23513/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/filesystem.py b/pySim/filesystem.py</span><br><span>index f6dddb6..ba94d8f 100644</span><br><span>--- a/pySim/filesystem.py</span><br><span>+++ b/pySim/filesystem.py</span><br><span>@@ -684,10 +684,10 @@</span><br><span> class CardApplication(object):</span><br><span>     """A card application is represented by an ADF (with contained hierarchy) and optionally</span><br><span>        some SW definitions."""</span><br><span style="color: hsl(0, 100%, 40%);">-    def __init__(self, name, adf=None, sw={}):</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, name, adf=None, sw=None):</span><br><span>         self.name = name</span><br><span>         self.adf = adf</span><br><span style="color: hsl(0, 100%, 40%);">-        self.sw = sw</span><br><span style="color: hsl(120, 100%, 40%);">+        self.sw = sw or dict()</span><br><span> </span><br><span>     def __str__(self):</span><br><span>         return "APP(%s)" % (self.name)</span><br><span>@@ -701,13 +701,13 @@</span><br><span>     """A Card Profile describes a card, it's filessystem hierarchy, an [initial] list of</span><br><span>        applications as well as profile-specific SW and shell commands.  Every card has</span><br><span>        one card profile, but there may be multiple applications within that profile."""</span><br><span style="color: hsl(0, 100%, 40%);">-    def __init__(self, name, desc=None, files_in_mf=[], sw=[], applications=[], shell_cmdsets=[]):</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, name, **kw):</span><br><span>         self.name = name</span><br><span style="color: hsl(0, 100%, 40%);">-        self.desc = desc</span><br><span style="color: hsl(0, 100%, 40%);">-        self.files_in_mf = files_in_mf</span><br><span style="color: hsl(0, 100%, 40%);">-        self.sw = sw</span><br><span style="color: hsl(0, 100%, 40%);">-        self.applications = applications</span><br><span style="color: hsl(0, 100%, 40%);">-        self.shell_cmdsets = shell_cmdsets</span><br><span style="color: hsl(120, 100%, 40%);">+        self.desc = kw.get("desc", None)</span><br><span style="color: hsl(120, 100%, 40%);">+  self.files_in_mf = kw.get("files_in_mf", [])</span><br><span style="color: hsl(120, 100%, 40%);">+        self.sw = kw.get("sw", [])</span><br><span style="color: hsl(120, 100%, 40%);">+        self.applications = kw.get("applications", [])</span><br><span style="color: hsl(120, 100%, 40%);">+        self.shell_cmdsets = kw.get("shell_cmdsets", [])</span><br><span> </span><br><span>     def __str__(self):</span><br><span>         return self.name</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/23513">change 23513</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/23513"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I83d718ff9c3ff6aef47930f38d7f50424f9b880f </div>
<div style="display:none"> Gerrit-Change-Number: 23513 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: fixeria <vyanitskiy@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>