[ovs-dev,07/55] python: Resolve pep8 comparison errors.
diff mbox

Message ID 1450730875-18083-8-git-send-email-russell@ovn.org
State Deferred
Headers show

Commit Message

Russell Bryant Dec. 21, 2015, 8:47 p.m. UTC
Resolve pep8 errors:

  E711 comparison to None should be 'if cond is None:'

The reason comparing against None with "is None" is preferred over
"== None" is because a class can define its own equality operator and
produce bizarre unexpected behavior.  Using "is None" has a very
explicit meaning that can not be overridden.

  E721 do not compare types, use 'isinstance()'

This one is actually a mistake by the tool.  The line of code looks like
it's using the types module from the Python stdlib, but it's actually
ovs.db.types.  Change the import to make this more clear and eliminate
the error.

Signed-off-by: Russell Bryant <russell@ovn.org>
---
 python/ovs/db/idl.py    |  2 +-
 python/ovs/db/parser.py |  2 +-
 python/ovs/db/schema.py | 10 ++++++----
 python/ovs/json.py      |  2 +-
 python/ovs/jsonrpc.py   |  2 +-
 python/tox.ini          |  2 +-
 6 files changed, 11 insertions(+), 9 deletions(-)

Patch
diff mbox

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 8d50f65..33ae9fe 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -179,7 +179,7 @@  class Idl(object):
             if (msg.type == ovs.jsonrpc.Message.T_NOTIFY
                 and msg.method == "update"
                 and len(msg.params) == 2
-                and msg.params[0] == None):
+                and msg.params[0] is None):
                 # Database contents changed.
                 self.__parse_update(msg.params[1])
             elif (msg.type == ovs.jsonrpc.Message.T_REPLY
diff --git a/python/ovs/db/parser.py b/python/ovs/db/parser.py
index 2556bec..81caedb 100644
--- a/python/ovs/db/parser.py
+++ b/python/ovs/db/parser.py
@@ -80,7 +80,7 @@  def is_identifier(s):
 
 
 def json_type_to_string(type_):
-    if type_ == None:
+    if type_ is None:
         return "null"
     elif type_ == bool:
         return "boolean"
diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py
index bc86232..263907e 100644
--- a/python/ovs/db/schema.py
+++ b/python/ovs/db/schema.py
@@ -17,7 +17,7 @@  import sys
 
 from ovs.db import error
 import ovs.db.parser
-from ovs.db import types
+import ovs.db.types
 
 
 def _check_id(name, json):
@@ -101,7 +101,8 @@  class DbSchema(object):
         return DbSchema.from_json(self.to_json())
 
     def __follow_ref_table(self, column, base, base_name):
-        if not base or base.type != types.UuidType or not base.ref_table_name:
+        if (not base or base.type != ovs.db.types.UuidType
+                or not base.ref_table_name):
             return
 
         base.ref_table = self.tables.get(base.ref_table_name)
@@ -181,7 +182,7 @@  class TableSchema(object):
         indexes_json = parser.get_optional("indexes", [list], [])
         parser.finish()
 
-        if max_rows == None:
+        if max_rows is None:
             max_rows = sys.maxint
         elif max_rows <= 0:
             raise error.Error("maxRows must be at least 1", json)
@@ -257,7 +258,8 @@  class ColumnSchema(object):
         parser = ovs.db.parser.Parser(json, "schema for column %s" % name)
         mutable = parser.get_optional("mutable", [bool], True)
         ephemeral = parser.get_optional("ephemeral", [bool], False)
-        type_ = types.Type.from_json(parser.get("type", [dict, str, unicode]))
+        type_ = ovs.db.types.Type.from_json(parser.get("type",
+                                                       [dict, str, unicode]))
         parser.finish()
 
         return ColumnSchema(name, mutable, not ephemeral, type_)
diff --git a/python/ovs/json.py b/python/ovs/json.py
index bfa9f5a..c71c640 100644
--- a/python/ovs/json.py
+++ b/python/ovs/json.py
@@ -579,7 +579,7 @@  class Parser(object):
         elif self.parse_state != Parser.__parse_end:
             self.__error("unexpected end of input")
 
-        if self.error == None:
+        if self.error is None:
             assert len(self.stack) == 1
             return self.stack.pop()
         else:
diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py
index d54d74b..f2873a4 100644
--- a/python/ovs/jsonrpc.py
+++ b/python/ovs/jsonrpc.py
@@ -490,7 +490,7 @@  class Session(object):
                 request.id = "echo"
                 self.rpc.send(request)
         else:
-            assert action == None
+            assert action is None
 
     def wait(self, poller):
         if self.rpc is not None:
diff --git a/python/tox.ini b/python/tox.ini
index 44bafd3..db123eb 100644
--- a/python/tox.ini
+++ b/python/tox.ini
@@ -16,5 +16,5 @@  deps = -r{toxinidir}/requirements.txt
 commands = flake8
 
 [flake8]
-ignore=E111,E113,E126,E127,E128,E129,E131,E201,E203,E226,E231,E241,E251,E261,E262,E265,E271,E501,E711,E721
+ignore=E111,E113,E126,E127,E128,E129,E131,E201,E203,E226,E231,E241,E251,E261,E262,E265,E271,E501
 exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build