Change in vdsm[master]: Get rid of mutables(lists) as default parameters
asegurap at redhat.com
asegurap at redhat.com
Wed Aug 21 09:59:16 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: Get rid of mutables(lists) as default parameters
......................................................................
Get rid of mutables(lists) as default parameters
In Python having a mutable as a default method parameter is
dangerous due to the fact that the mutables are created on
module creation rather than on method invokation. Thus, a
call to a method could pollute the environment for the next
call.
This patch cleans most instances of that happening.
Change-Id: I911485cf30d587f5b6b8bf44cf3552c1517abfd5
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm/API.py
M vdsm/BindingXMLRPC.py
M vdsm/gluster/exception.py
M vdsm/storage/fileUtils.py
M vdsm/storage/lvm.py
M vdsm/storage/misc.py
M vdsm/storage/outOfProcess.py
M vdsm/vm.py
8 files changed, 20 insertions(+), 15 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/56/18356/1
diff --git a/vdsm/API.py b/vdsm/API.py
index 37bb908..efc7081 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -1230,7 +1230,7 @@
return dict(status=doneCode)
# VM-related functions
- def getVMList(self, fullStatus=False, vmList=[]):
+ def getVMList(self, fullStatus=False, vmList=()):
""" return a list of known VMs with full (or partial) config each """
def reportedStatus(v, full):
diff --git a/vdsm/BindingXMLRPC.py b/vdsm/BindingXMLRPC.py
index fb65ad4..0c67ebe 100644
--- a/vdsm/BindingXMLRPC.py
+++ b/vdsm/BindingXMLRPC.py
@@ -214,7 +214,7 @@
vm = API.VM(vmParams['vmId'])
return vm.create(vmParams)
- def getVMList(self, fullStatus=False, vmList=[]):
+ def getVMList(self, fullStatus=False, vmList=None):
api = API.Global()
return api.getVMList(fullStatus, vmList)
diff --git a/vdsm/gluster/exception.py b/vdsm/gluster/exception.py
index c569a9e..b61af73 100644
--- a/vdsm/gluster/exception.py
+++ b/vdsm/gluster/exception.py
@@ -40,10 +40,10 @@
out = []
err = []
- def __init__(self, rc=0, out=[], err=[]):
+ def __init__(self, rc=0, out=None, err=None):
self.rc = rc
- self.out = out
- self.err = err
+ self.out = [] if out is None else out
+ self.err = [] if err is None else err
def __str__(self):
o = '\n'.join(self.out)
diff --git a/vdsm/storage/fileUtils.py b/vdsm/storage/fileUtils.py
index 6090a07..d883190 100644
--- a/vdsm/storage/fileUtils.py
+++ b/vdsm/storage/fileUtils.py
@@ -51,7 +51,7 @@
pass
-def tarCopy(src, dst, exclude=[]):
+def tarCopy(src, dst, exclude=()):
excludeArgs = ["--exclude=%s" % path for path in exclude]
tsrc = subprocess.Popen([constants.EXT_TAR, "cf", "-"] +
diff --git a/vdsm/storage/lvm.py b/vdsm/storage/lvm.py
index bc9d30c..2f91e54 100644
--- a/vdsm/storage/lvm.py
+++ b/vdsm/storage/lvm.py
@@ -1160,7 +1160,7 @@
raise se.MissingTagOnLogicalVolume("%s/%s" % (vg, lv), tag)
-def changeLVTags(vg, lv, delTags=[], addTags=[]):
+def changeLVTags(vg, lv, delTags=(), addTags=()):
lvname = '%s/%s' % (vg, lv)
delTags = set(delTags)
addTags = set(addTags)
@@ -1218,7 +1218,7 @@
return os.path.exists(lvPath(vgName, lvName))
-def changeVGTags(vgName, delTags=[], addTags=[]):
+def changeVGTags(vgName, delTags=(), addTags=()):
delTags = set(delTags)
addTags = set(addTags)
if delTags.intersection(addTags):
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index fe3a870..8dac036 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -124,14 +124,17 @@
return False
-def findCaller(skipUp=0, ignoreSourceFiles=[], ignoreMethodNames=[],
+def findCaller(skipUp=0, ignoreSourceFiles=None, ignoreMethodNames=None,
logSkipName=None):
"""
Find the stack frame of the caller so that we can note the source
file name, line number and function name.
"""
# Ignore file extension can be either py or pyc
- ignoreSourceFiles = ignoreSourceFiles + [logging._srcfile]
+ if ignoreSourceFiles is None:
+ ignoreSourceFiles = [logging._srcfile]
+ else:
+ ignoreSourceFiles += [logging._srcfile]
ignoreSourceFiles = [os.path.splitext(sf)[0] for sf in ignoreSourceFiles]
frame = inspect.currentframe().f_back
@@ -141,8 +144,10 @@
code = frame.f_code
filename = os.path.normcase(code.co_filename)
- logSkip = _shouldLogSkip(skipUp, ignoreSourceFiles, ignoreMethodNames,
- logSkipName, code, filename)
+ logSkip = _shouldLogSkip(
+ skipUp, ignoreSourceFiles,
+ [] if ignoreMethodNames is None else ignoreMethodNames,
+ logSkipName, code, filename)
if logSkip:
skipUp -= 1
@@ -1116,7 +1121,7 @@
pass
-def walk(top, topdown=True, onerror=None, followlinks=False, blacklist=[]):
+def walk(top, topdown=True, onerror=None, followlinks=False, blacklist=()):
"""Directory tree generator.
Custom implementation of os.walk that doesn't block if the destination of
diff --git a/vdsm/storage/outOfProcess.py b/vdsm/storage/outOfProcess.py
index bf61d54..65d29e9 100644
--- a/vdsm/storage/outOfProcess.py
+++ b/vdsm/storage/outOfProcess.py
@@ -51,7 +51,7 @@
class _ModuleWrapper(types.ModuleType):
- def __init__(self, modName, procPool, timeout, subModNames=[]):
+ def __init__(self, modName, procPool, timeout, subModNames=()):
self._modName = modName
self._procPool = procPool
self._timeout = timeout
diff --git a/vdsm/vm.py b/vdsm/vm.py
index 9a24822..c6f84b3 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -1147,7 +1147,7 @@
if not a.startswith('__')]
return ' '.join(attrs)
- def createXmlElem(self, elemType, deviceType, attributes=[]):
+ def createXmlElem(self, elemType, deviceType, attributes=()):
"""
Create domxml device element according to passed in params
"""
--
To view, visit http://gerrit.ovirt.org/18356
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I911485cf30d587f5b6b8bf44cf3552c1517abfd5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the vdsm-patches
mailing list