Fix pylint 'E' (error) codes
authorIustin Pop <iustin@google.com>
Wed, 4 Nov 2009 13:09:53 +0000 (14:09 +0100)
committerIustin Pop <iustin@google.com>
Fri, 6 Nov 2009 13:48:36 +0000 (14:48 +0100)
This patch adds some silences and tweaks the code slightly so that
“pylint --rcfile pylintrc -e ganeti” doesn't give any errors.

The biggest change is in jqueue.py, the move of _RequireOpenQueue out of
the JobQueue class. Since that is actually a function and not a method
(never used as such) this makes sense, and also silences two pylint
errors.

Another real code change is in utils.py, where FieldSet.Matches will
return None instead of False for failure; this still works with the way
this class/method is used, and makes more sense (it resembles more
closely the re.match return values).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/backend.py
lib/confd/client.py
lib/http/client.py
lib/jqueue.py
lib/objects.py
lib/storage.py
lib/utils.py

index 3aac250..2961371 100644 (file)
 
 """
 
+# pylint: disable-msg=E1103
+
+# E1103: %s %r has no %r member (but some types could not be
+# inferred), because the _TryOSFromDisk returns either (True, os_obj)
+# or (False, "string") which confuses pylint
+
 
 import os
 import os.path
index db9a71c..674a2ca 100644 (file)
@@ -45,6 +45,11 @@ confirming what you already got.
 
 """
 
+# pylint: disable-msg=E0203
+
+# E0203: Access to member %r before its definition, since we use
+# objects.py which doesn't explicitely initialise its members
+
 import socket
 import time
 import random
@@ -400,4 +405,3 @@ class ConfdFilterCallback:
 
     if not filter_upcall:
       self._callback(up)
-
index 717581f..5b76cf3 100644 (file)
 
 """
 
+# pylint: disable-msg=E1103
+
+# # E1103: %s %r has no %r member (but some types could not be
+# inferred), since _socketobject could be ssl or not and pylint
+# doesn't parse that
+
+
 import os
 import select
 import socket
index 73d6a0e..9f1d5be 100644 (file)
@@ -540,33 +540,37 @@ class _JobQueueWorkerPool(workerpool.WorkerPool):
     self.queue = queue
 
 
-class JobQueue(object):
-  """Queue used to manage the jobs.
+def _RequireOpenQueue(fn):
+  """Decorator for "public" functions.
 
-  @cvar _RE_JOB_FILE: regex matching the valid job file names
+  This function should be used for all 'public' functions. That is,
+  functions usually called from other classes. Note that this should
+  be applied only to methods (not plain functions), since it expects
+  that the decorated function is called with a first argument that has
+  a '_queue_lock' argument.
 
-  """
-  _RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
+  @warning: Use this decorator only after utils.LockedMethod!
 
-  def _RequireOpenQueue(fn):
-    """Decorator for "public" functions.
+  Example::
+    @utils.LockedMethod
+    @_RequireOpenQueue
+    def Example(self):
+      pass
 
-    This function should be used for all 'public' functions. That is,
-    functions usually called from other classes.
+  """
+  def wrapper(self, *args, **kwargs):
+    assert self._queue_lock is not None, "Queue should be open"
+    return fn(self, *args, **kwargs)
+  return wrapper
 
-    @warning: Use this decorator only after utils.LockedMethod!
 
-    Example::
-      @utils.LockedMethod
-      @_RequireOpenQueue
-      def Example(self):
-        pass
+class JobQueue(object):
+  """Queue used to manage the jobs.
 
-    """
-    def wrapper(self, *args, **kwargs):
-      assert self._queue_lock is not None, "Queue should be open"
-      return fn(self, *args, **kwargs)
-    return wrapper
+  @cvar _RE_JOB_FILE: regex matching the valid job file names
+
+  """
+  _RE_JOB_FILE = re.compile(r"^job-(%s)$" % constants.JOB_ID_TEMPLATE)
 
   def __init__(self, context):
     """Constructor for JobQueue.
index 06bc7e0..2f3b4f6 100644 (file)
@@ -26,6 +26,11 @@ pass to and from external parties.
 
 """
 
+# pylint: disable-msg=E0203
+
+# E0203: Access to member %r before its definition, since we use
+# objects.py which doesn't explicitely initialise its members
+
 
 import ConfigParser
 import re
index 7f73100..b4b303a 100644 (file)
@@ -328,6 +328,7 @@ class LvmPvStorage(_LvmBase):
   """LVM Physical Volume storage unit.
 
   """
+  @staticmethod
   def _GetAllocatable(attr):
     if attr:
       return (attr[0] == "a")
index ec7fec8..65ef2c3 100644 (file)
@@ -2413,12 +2413,12 @@ class FieldSet(object):
 
     @type field: str
     @param field: the string to match
-    @return: either False or a regular expression match object
+    @return: either None or a regular expression match object
 
     """
     for m in itertools.ifilter(None, (val.match(field) for val in self.items)):
       return m
-    return False
+    return None
 
   def NonMatching(self, items):
     """Returns the list of fields not matching the current set