[blivet:master 1/5] Do not set parents attribute if parents param is bad.
mulhern
amulhern at redhat.com
Mon Oct 6 13:14:48 UTC 2014
Wait until after the check.
Also, if somehow parents parameter is 0 or "" or {}, ValueError is raised.
Previously it would only have been raised in cases where parents evaluated
to True for purposes of an if condition, like 2 or "hello".
Main benefit is that new code is easier to understand.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devices/device.py | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/blivet/devices/device.py b/blivet/devices/device.py
index 498fef4..9e0d8d0 100644
--- a/blivet/devices/device.py
+++ b/blivet/devices/device.py
@@ -84,12 +84,10 @@ class Device(util.ObjectID):
raise ValueError("%s is not a valid name for this device" % name)
self._name = name
- self.parents = []
- if parents and not isinstance(parents, list):
+ if parents is not None and not isinstance(parents, list):
raise ValueError("parents must be a list of Device instances")
- if parents:
- self.parents = parents
+ self.parents = parents or []
def __deepcopy__(self, memo):
""" Create a deep copy of a Device instance.
--
1.9.3
More information about the anaconda-patches
mailing list