[blivet:master 02/14] Change param default [] to None and convert in method

mulhern amulhern at redhat.com
Fri Mar 28 22:50:27 UTC 2014


A default of [] (or any mutable structure) is considered dangerous because the
default argument is packed up with the function at its definition. Thus, the
same object is shared among all execution instances of the function that
are called with the default argument.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicelibs/lvm.py    | 5 ++++-
 blivet/devicelibs/mdraid.py | 7 +++++--
 scripts/makeupdates         | 4 +++-
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index bc6d563..c073022 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -454,7 +454,10 @@ def lvorigin(vg_name, lv_name):
 
     return origin
 
-def lvcreate(vg_name, lv_name, size, pvs=[]):
+def lvcreate(vg_name, lv_name, size, pvs=None):
+    if pvs is None:
+        pvs = []
+
     args = ["lvcreate"] + \
             ["-L", "%dm" % size.convertTo(spec="mib")] + \
             ["-n", lv_name] + \
diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index 1fb0bd9..142d49f 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -191,7 +191,7 @@ def mdremove(array, device, fail=False):
     except MDRaidError as msg:
         raise MDRaidError("mdremove failed for %s: %s" % (device, msg))
 
-def mdactivate(device, members=[], uuid=None):
+def mdactivate(device, members=None, uuid=None):
     """Assemble devices given by members into a single device.
 
        Use uuid value to identify devices in members to include in device.
@@ -199,8 +199,11 @@ def mdactivate(device, members=[], uuid=None):
        :param device: the device to be assembled
        :param type: str
        :param members: the component devices
-       :param type: list of str
+       :param type: list of str or NoneType
     """
+    if members is None:
+        members = []
+
     if not uuid:
         raise MDRaidError("mdactivate requires a uuid")
 
diff --git a/scripts/makeupdates b/scripts/makeupdates
index 2bd15e8..cc040ea 100755
--- a/scripts/makeupdates
+++ b/scripts/makeupdates
@@ -73,7 +73,9 @@ def getArchiveTagOffset(spec, offset, name="blivet"):
     except IndexError:
         return tag
 
-def doGitDiff(tag, args=[]):
+def doGitDiff(tag, args=None):
+    if args is None:
+        args = []
     proc = subprocess.Popen(['git', 'diff', '--name-status', tag] + args,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE).communicate()
-- 
1.8.3.1



More information about the anaconda-patches mailing list