From d101d3bce8c59583c5713215b6a7fb2f7376a1fc Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 22 Aug 2013 11:16:03 +0200 Subject: Test for object identity when checking for None in Python Consistently use "is" or "is not" to compare variables to None, because doing so is preferrable, as per PEP 8 (http://www.python.org/dev/peps/pep-0008/#programming-recommendations): > Comparisons to singletons like None should always be done with is or > is not, never the equality operators. --- generator.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'generator.py') diff --git a/generator.py b/generator.py index 427cebc..6c7414a 100755 --- a/generator.py +++ b/generator.py @@ -136,7 +136,7 @@ class docParser(xml.sax.handler.ContentHandler): print "end %s" % tag if tag == 'function': # fuctions come from source files, hence 'virerror.c' - if self.function != None: + if self.function is not None: if (self.function_module == "libvirt" or self.function_module == "virevent" or self.function_module == "virerror"): @@ -641,9 +641,9 @@ def print_function_wrapper(module, name, output, export, include): (f, t, n, c) = py_types[arg[1]] if (f == 'z') and (name in foreign_encoding_args) and (num_bufs == 0): f = 't#' - if f != None: + if f is not None: format = format + f - if t != None: + if t is not None: format_args = format_args + ", &pyobj_%s" % (arg[0]) c_args = c_args + " PyObject *pyobj_%s;\n" % (arg[0]) c_convert = c_convert + \ @@ -686,7 +686,7 @@ def print_function_wrapper(module, name, output, export, include): elif py_types.has_key(ret[0]): (f, t, n, c) = py_types[ret[0]] c_return = " %s c_retval;\n" % (ret[0]) - if file == "python_accessor" and ret[2] != None: + if file == "python_accessor" and ret[2] is not None: c_call = "\n c_retval = %s->%s;\n" % (args[0][0], ret[2]) else: c_call = "\n c_retval = %s(%s);\n" % (name, c_call) @@ -708,7 +708,7 @@ def print_function_wrapper(module, name, output, export, include): unknown_types[ret[0]] = [name] return -1 - if cond != None and cond != "": + if cond is not None and cond != "": include.write("#if %s\n" % cond) export.write("#if %s\n" % cond) output.write("#if %s\n" % cond) @@ -729,14 +729,14 @@ def print_function_wrapper(module, name, output, export, include): if file == "python": # Those have been manually generated - if cond != None and cond != "": + if cond is not None and cond != "": include.write("#endif\n") export.write("#endif\n") output.write("#endif\n") return 1 if file == "python_accessor" and ret[0] != "void" and ret[2] is None: # Those have been manually generated - if cond != None and cond != "": + if cond is not None and cond != "": include.write("#endif\n") export.write("#endif\n") output.write("#endif\n") @@ -771,7 +771,7 @@ def print_function_wrapper(module, name, output, export, include): output.write(" LIBVIRT_END_ALLOW_THREADS;\n") output.write(ret_convert) output.write("}\n\n") - if cond != None and cond != "": + if cond is not None and cond != "": include.write("#endif /* %s */\n" % cond) export.write("#endif /* %s */\n" % cond) output.write("#endif /* %s */\n" % cond) @@ -1313,7 +1313,7 @@ def buildWrappers(module): classes.write("#\n") classes.write("# WARNING WARNING WARNING WARNING\n") classes.write("#\n") - if extra != None: + if extra is not None: classes.writelines(extra.readlines()) classes.write("#\n") classes.write("# WARNING WARNING WARNING WARNING\n") @@ -1321,7 +1321,7 @@ def buildWrappers(module): classes.write("# Automatically written part of python bindings for libvirt\n") classes.write("#\n") classes.write("# WARNING WARNING WARNING WARNING\n") - if extra != None: + if extra is not None: extra.close() if function_classes.has_key("None"): @@ -1460,7 +1460,7 @@ def buildWrappers(module): destruct=None if classes_destructors.has_key(classname): classes.write(" def __del__(self):\n") - classes.write(" if self._o != None:\n") + classes.write(" if self._o is not None:\n") classes.write(" libvirtmod.%s(self._o)\n" % classes_destructors[classname]) classes.write(" self._o = None\n\n") @@ -1776,7 +1776,7 @@ def qemuBuildWrappers(module): fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("#\n") - if extra != None: + if extra is not None: fd.writelines(extra.readlines()) fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") @@ -1784,7 +1784,7 @@ def qemuBuildWrappers(module): fd.write("# Automatically written part of python bindings for libvirt\n") fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") - if extra != None: + if extra is not None: extra.close() fd.write("try:\n") @@ -1888,7 +1888,7 @@ def lxcBuildWrappers(module): fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") fd.write("#\n") - if extra != None: + if extra is not None: fd.writelines(extra.readlines()) fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") @@ -1896,7 +1896,7 @@ def lxcBuildWrappers(module): fd.write("# Automatically written part of python bindings for libvirt\n") fd.write("#\n") fd.write("# WARNING WARNING WARNING WARNING\n") - if extra != None: + if extra is not None: extra.close() fd.write("try:\n") -- cgit