There are too many cases where we deliberately wrap expressions in
parens, either to indicate comparisons, or to allow multiline
expressions without line continuation chars, or to clarify confusing
precedence.

While here, clean up a few unpythonic cases.

Signed-off-by: Brian Foley <bpfo...@google.com>
---
 Makefile.am                       | 6 +++++-
 lib/bootstrap.py                  | 2 +-
 lib/cli.py                        | 2 +-
 lib/client/gnt_cluster.py         | 2 +-
 lib/cmdlib/instance_set_params.py | 4 ++--
 lib/netutils.py                   | 2 +-
 lib/utils/process.py              | 4 ++--
 7 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 19101ca..88d30c6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2691,7 +2691,11 @@ PEP8_EXCLUDE = $(subst $(space),$(comma),$(strip 
$(notdir $(built_python_sources
 # R0204 = disable redefined-variable-type warning. There are a large number of
 #         cases where Ganeti assigns multiple types (eg set/list, float/int) to
 #         the same variable, and these are benign.
-LINT_DISABLE = I0013 R0912 R0204
+# C0325 = disable superfluous-parens. There are a lot of cases where this is
+#         overzealous, eg where we use parens to make it clear that we're
+#         deliberately doing a comparison that should yield bool, or are using
+#         parens clarify precedence or to allow multi-line expressions.
+LINT_DISABLE = I0013 R0912 R0204 C0325
 # Additional pylint options
 LINT_OPTS =
 # The combined set of pylint options
diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 7b6fbfe..0a382c5 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -678,7 +678,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: 
disable=R0913, R0914
   for template, dt_params in diskparams.items():
     param_keys = set(dt_params.keys())
     default_param_keys = set(constants.DISK_DT_DEFAULTS[template].keys())
-    if not (param_keys <= default_param_keys):
+    if param_keys > default_param_keys:
       unknown_params = param_keys - default_param_keys
       raise errors.OpPrereqError("Invalid parameters for disk template %s:"
                                  " %s" % (template,
diff --git a/lib/cli.py b/lib/cli.py
index f01d8d9..14bd4ea 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -2944,7 +2944,7 @@ def _NotAContainer(data):
   @rtype: bool
 
   """
-  return not (isinstance(data, (list, dict, tuple)))
+  return not isinstance(data, (list, dict, tuple))
 
 
 def _GetAlignmentMapping(data):
diff --git a/lib/client/gnt_cluster.py b/lib/client/gnt_cluster.py
index 3eaf292..b32e62e 100644
--- a/lib/client/gnt_cluster.py
+++ b/lib/client/gnt_cluster.py
@@ -195,7 +195,7 @@ def InitCluster(opts, args):
   # check the disk template types here, as we cannot rely on the type check 
done
   # by the opcode parameter types
   diskparams_keys = set(diskparams.keys())
-  if not (diskparams_keys <= constants.DISK_TEMPLATES):
+  if not diskparams_keys > constants.DISK_TEMPLATES:
     unknown = utils.NiceSort(diskparams_keys - constants.DISK_TEMPLATES)
     ToStderr("Disk templates unknown: %s" % utils.CommaJoin(unknown))
     return 1
diff --git a/lib/cmdlib/instance_set_params.py 
b/lib/cmdlib/instance_set_params.py
index a35e95c..9ffbfdf 100644
--- a/lib/cmdlib/instance_set_params.py
+++ b/lib/cmdlib/instance_set_params.py
@@ -1260,7 +1260,7 @@ class LUInstanceSetParams(LogicalUnit):
       res_min = ComputeIPolicyInstanceSpecViolation(ipolicy, ispec_min,
                                                     new_disk_types)
 
-      if (res_max or res_min):
+      if res_max or res_min:
         # FIXME: Improve error message by including information about whether
         # the upper or lower limit of the parameter fails the ipolicy.
         msg = ("Instance allocation to group %s (%s) violates policy: %s" %
@@ -1628,7 +1628,7 @@ class LUInstanceSetParams(LogicalUnit):
     disk = self.GenericGetDiskInfo(uuid, name)
 
     # Rename disk before attaching (if disk is filebased)
-    if disk.dev_type in (constants.DTS_INSTANCE_DEPENDENT_PATH):
+    if disk.dev_type in constants.DTS_INSTANCE_DEPENDENT_PATH:
       # Add disk size/mode, else GenerateDiskTemplate will not work.
       params[constants.IDISK_SIZE] = disk.size
       params[constants.IDISK_MODE] = str(disk.mode)
diff --git a/lib/netutils.py b/lib/netutils.py
index 2eada25..ab94723 100644
--- a/lib/netutils.py
+++ b/lib/netutils.py
@@ -428,7 +428,7 @@ class IPAddress(object):
     @return: True if valid, False otherwise
 
     """
-    assert (isinstance(netmask, (int, long)))
+    assert isinstance(netmask, (int, long))
 
     return 0 < netmask <= cls.iplen
 
diff --git a/lib/utils/process.py b/lib/utils/process.py
index 29d8b0c..9183e9f 100644
--- a/lib/utils/process.py
+++ b/lib/utils/process.py
@@ -934,12 +934,12 @@ def Daemonize(logfile):
 
   # this might fail
   pid = os.fork()
-  if (pid == 0):  # The first child.
+  if pid == 0:  # The first child.
     SetupDaemonEnv()
 
     # this might fail
     pid = os.fork() # Fork a second child.
-    if (pid == 0):  # The second child.
+    if pid == 0:  # The second child.
       utils_wrapper.CloseFdNoError(rpipe)
     else:
       # exit() or _exit()?  See below.
-- 
2.8.0.rc3.226.g39d4020

Reply via email to