[ovs-dev] [python 07/31] python: Avoid using 'type' as a variable name.

Ben Pfaff blp at nicira.com
Tue Aug 23 21:05:01 UTC 2011


'type' is a Python built-in function, so it's best to avoid using it as
a variable name.

Reported-by: Reid Price <reid at nicira.com>
---
 python/ovs/db/data.py   |   26 +++++++++++++-------------
 python/ovs/db/parser.py |   14 +++++++-------
 python/ovs/db/schema.py |    4 ++--
 python/ovs/jsonrpc.py   |   10 +++++-----
 python/ovs/process.py   |    6 +++---
 python/ovs/reconnect.py |   10 +++++-----
 6 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/python/ovs/db/data.py b/python/ovs/db/data.py
index 7cf5eac..a34dced 100644
--- a/python/ovs/db/data.py
+++ b/python/ovs/db/data.py
@@ -64,12 +64,12 @@ def returnUnchanged(x):
     return x
 
 class Atom(object):
-    def __init__(self, type, value=None):
-        self.type = type
+    def __init__(self, type_, value=None):
+        self.type = type_
         if value is not None:
             self.value = value
         else:
-            self.value = type.default_atom()
+            self.value = type_.default_atom()
 
     def __cmp__(self, other):
         if not isinstance(other, Atom) or self.type != other.type:
@@ -85,8 +85,8 @@ class Atom(object):
         return hash(self.value)
 
     @staticmethod
-    def default(type):
-        return Atom(type)
+    def default(type_):
+        return Atom(type_)
 
     def is_default(self):
         return self == self.default(self.type)
@@ -227,8 +227,8 @@ class Atom(object):
         return Atom(t, x)
 
 class Datum(object):
-    def __init__(self, type, values={}):
-        self.type = type
+    def __init__(self, type_, values={}):
+        self.type = type_
         self.values = values
 
     def __cmp__(self, other):
@@ -250,14 +250,14 @@ class Datum(object):
         return Datum(self.type, dict(self.values))
 
     @staticmethod
-    def default(type):
-        if type.n_min == 0:
+    def default(type_):
+        if type_.n_min == 0:
             values = {}
-        elif type.is_map():
-            values = {type.key.default(): type.value.default()}
+        elif type_.is_map():
+            values = {type_.key.default(): type_.value.default()}
         else:
-            values = {type.key.default(): None}
-        return Datum(type, values)
+            values = {type_.key.default(): None}
+        return Datum(type_, values)
 
     def is_default(self):
         return self == default(self.type)
diff --git a/python/ovs/db/parser.py b/python/ovs/db/parser.py
index 073f760..67b3bd5 100644
--- a/python/ovs/db/parser.py
+++ b/python/ovs/db/parser.py
@@ -75,18 +75,18 @@ id_re = re.compile("[_a-zA-Z][_a-zA-Z0-9]*$")
 def is_identifier(s):
     return type(s) in [str, unicode] and id_re.match(s)
 
-def json_type_to_string(type):
-    if type == None:
+def json_type_to_string(type_):
+    if type_ == None:
         return "null"
-    elif type == bool:
+    elif type_ == bool:
         return "boolean"
-    elif type == dict:
+    elif type_ == dict:
         return "object"
-    elif type == list:
+    elif type_ == list:
         return "array"
-    elif type in [int, long, float]:
+    elif type_ in [int, long, float]:
         return "number"
-    elif type in [str, unicode]:
+    elif type_ in [str, unicode]:
         return "string"
     else:
         return "<invalid>"
diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py
index e76d6f6..2d053a0 100644
--- a/python/ovs/db/schema.py
+++ b/python/ovs/db/schema.py
@@ -239,11 +239,11 @@ class TableSchema(object):
         return json
 
 class ColumnSchema(object):
-    def __init__(self, name, mutable, persistent, type):
+    def __init__(self, name, mutable, persistent, type_):
         self.name = name
         self.mutable = mutable
         self.persistent = persistent
-        self.type = type
+        self.type = type_
         self.unique = False
 
     @staticmethod
diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py
index 2e3c2e0..906e93c 100644
--- a/python/ovs/jsonrpc.py
+++ b/python/ovs/jsonrpc.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2011 Nicira Networks
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -36,8 +36,8 @@ class Message(object):
                T_ERROR: "error"}
     __next_id = 0
 
-    def __init__(self, type, method, params, result, error, id):
-        self.type = type
+    def __init__(self, type_, method, params, result, error, id):
+        self.type = type_
         self.method = method
         self.params = params
         self.result = result
@@ -70,8 +70,8 @@ class Message(object):
         return Message(Message.T_ERROR, None, None, None, error, id)
 
     @staticmethod
-    def type_to_string(type):
-        return Message.__types[type]
+    def type_to_string(type_):
+        return Message.__types[type_]
 
     @staticmethod
     def __validate_arg(value, name, must_have):
diff --git a/python/ovs/process.py b/python/ovs/process.py
index 7367f79..f8182f1 100644
--- a/python/ovs/process.py
+++ b/python/ovs/process.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2011 Nicira Networks
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -15,8 +15,8 @@
 import os
 import signal
 
-def _signal_status_msg(type, signr):
-    s = "%s by signal %d" % (type, signr)
+def _signal_status_msg(type_, signr):
+    s = "%s by signal %d" % (type_, signr)
     for name in signal.__dict__:
         if name.startswith("SIG") and getattr(signal, name) == signr:
             return "%s (%s)" % (s, name)
diff --git a/python/ovs/reconnect.py b/python/ovs/reconnect.py
index 5fc96bc..757e730 100644
--- a/python/ovs/reconnect.py
+++ b/python/ovs/reconnect.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2010 Nicira Networks
+# Copyright (c) 2010, 2011 Nicira Networks
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -332,15 +332,15 @@ class Reconnect(object):
                                     % self.name)
             else:
                 if self.passive:
-                    type = "listen"
+                    type_ = "listen"
                 else:
-                    type = "connection"
+                    type_ = "connection"
                 if error > 0:
                     logging.warning("%s: %s attempt failed (%s)"
-                                    % (self.name, type, os.strerror(error)))
+                                    % (self.name, type_, os.strerror(error)))
                 else:
                     self.info_level("%s: %s attempt timed out"
-                                    % (self.name, type))
+                                    % (self.name, type_))
 
             if (self.state in (Reconnect.Active, Reconnect.Idle)):
                 self.last_disconnected = now
-- 
1.7.4.4




More information about the dev mailing list