scripts: Compare to `None` using `is` operator
authorMichał Janiszewski <janisozaur+signed@gmail.com>
Tue, 30 Oct 2018 22:22:03 +0000 (23:22 +0100)
committerLenny Komow <lenny@lunarg.com>
Thu, 1 Nov 2018 19:26:26 +0000 (13:26 -0600)
This is a trivial change that replaces `==` operator with `is` operator, following PEP 8 guideline:

> Comparisons to singletons like None should always be done with is or is not, never the equality operators.

https://legacy.python.org/dev/peps/pep-0008/#programming-recommendations

Change-Id: I4f9f6c921e4158365d4e41965bfcd43b7a3c07e0

scripts/dispatch_table_helper_generator.py
scripts/helper_file_generator.py
scripts/loader_extension_generator.py
scripts/loader_genvk.py

index 1e2412c0c5283fea657b81ae63757e938bae79c0..2ef9663104f74b7b3c43a385d5e41c05502479bf 100644 (file)
@@ -160,7 +160,7 @@ class DispatchTableHelperOutputGenerator(OutputGenerator):
     # Determine if this API should be ignored or added to the instance or device dispatch table
     def AddCommandToDispatchList(self, name, handle_type, protect, cmdinfo):
         handle = self.registry.tree.find("types/type/[name='" + handle_type + "'][@category='handle']")
-        if handle == None:
+        if handle is None:
             return
         if handle_type != 'VkInstance' and handle_type != 'VkPhysicalDevice' and name != 'vkGetInstanceProcAddr':
             self.device_dispatch_list.append((name, self.featureExtraProtect))
index f35ba405830a846ae8b87b7a5238510e45d6c34e..9d7ecdb3dca41816a36626a8efc258af57a77dfa 100644 (file)
@@ -192,7 +192,7 @@ class HelperFileOutputGenerator(OutputGenerator):
         if self.helper_file_type == 'enum_string_header':
             value_set = set()
             for elem in groupElem.findall('enum'):
-                if elem.get('supported') != 'disabled' and elem.get('alias') == None:
+                if elem.get('supported') != 'disabled' and elem.get('alias') is None:
                     value_set.add(elem.get('name'))
             self.enum_output += self.GenerateEnumStringConversion(groupName, value_set)
         elif self.helper_file_type == 'object_types_header':
@@ -437,7 +437,7 @@ class HelperFileOutputGenerator(OutputGenerator):
         for item in self.structMembers:
             if self.NeedSafeStruct(item) == True:
                 safe_struct_header += '\n'
-                if item.ifdef_protect != None:
+                if item.ifdef_protect is not None:
                     safe_struct_header += '#ifdef %s\n' % item.ifdef_protect
                 safe_struct_header += 'struct safe_%s {\n' % (item.name)
                 for member in item.members:
@@ -463,7 +463,7 @@ class HelperFileOutputGenerator(OutputGenerator):
                 safe_struct_header += '    %s *ptr() { return reinterpret_cast<%s *>(this); }\n' % (item.name, item.name)
                 safe_struct_header += '    %s const *ptr() const { return reinterpret_cast<%s const *>(this); }\n' % (item.name, item.name)
                 safe_struct_header += '};\n'
-                if item.ifdef_protect != None:
+                if item.ifdef_protect is not None:
                     safe_struct_header += '#endif // %s\n' % item.ifdef_protect
         return safe_struct_header
     #
@@ -803,7 +803,7 @@ class HelperFileOutputGenerator(OutputGenerator):
                 continue
             if item.name in wsi_structs:
                 continue
-            if item.ifdef_protect != None:
+            if item.ifdef_protect is not None:
                 safe_struct_body.append("#ifdef %s\n" % item.ifdef_protect)
             ss_name = "safe_%s" % item.name
             init_list = ''          # list of members in struct constructor initializer
@@ -1111,7 +1111,7 @@ class HelperFileOutputGenerator(OutputGenerator):
             init_copy = copy_construct_init.replace('src.', 'src->')
             init_construct = copy_construct_txt.replace('src.', 'src->')
             safe_struct_body.append("\nvoid %s::initialize(const %s* src)\n{\n%s%s}" % (ss_name, ss_name, init_copy, init_construct))
-            if item.ifdef_protect != None:
+            if item.ifdef_protect is not None:
                 safe_struct_body.append("#endif // %s\n" % item.ifdef_protect)
         return "\n".join(safe_struct_body)
     #
@@ -1203,7 +1203,7 @@ class HelperFileOutputGenerator(OutputGenerator):
             if not info:
                 continue
 
-            if item.ifdef_protect != None:
+            if item.ifdef_protect is not None:
                 code.append('#ifdef %s' % item.ifdef_protect)
 
             code.append('// Map type {} to id {}'.format(typename, info.value))
@@ -1211,7 +1211,7 @@ class HelperFileOutputGenerator(OutputGenerator):
                 id_decl=id_decl, id_member=id_member))
             code.append(idmap_format.format(template=idmap, typename=typename, id_value=info.value, typedef=type_member))
 
-            if item.ifdef_protect != None:
+            if item.ifdef_protect is not None:
                 code.append('#endif // %s' % item.ifdef_protect)
 
         # Generate utilities for all types
index 827c45989845c8616bc4236ea0d3d9f2207138ac..199dee10b9fe885d95ab0f4e6f171e703ad8f59a 100644 (file)
@@ -304,7 +304,7 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
         handle = self.registry.tree.find("types/type/[name='" + handle_type + "'][@category='handle']")
 
         return_type =  cmdinfo.elem.find('proto/type')
-        if (return_type != None and return_type.text == 'void'):
+        if (return_type is not None and return_type.text == 'void'):
            return_type = None
 
         cmd_params = []
@@ -326,7 +326,7 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
             cmd_params.append(self.CommandParam(type=param_type, name=param_name,
                                                 cdecl=param_cdecl))
 
-        if handle != None and handle_type != 'VkInstance' and handle_type != 'VkPhysicalDevice':
+        if handle is not None and handle_type != 'VkInstance' and handle_type != 'VkPhysicalDevice':
             # The Core Vulkan code will be wrapped in a feature called VK_VERSION_#_#
             # For example: VK_VERSION_1_0 wraps the core 1.0 Vulkan functionality
             if 'VK_VERSION_' in extension_name:
@@ -697,13 +697,13 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                 if cur_cmd.name in PRE_INSTANCE_FUNCTIONS:
                     mod_string = mod_string.replace(cur_cmd.name[2:] + '(\n', cur_cmd.name[2:] + '(\n    const Vk' + cur_cmd.name[2:] + 'Chain* chain,\n')
 
-                if (cur_cmd.protect != None):
+                if (cur_cmd.protect is not None):
                     terminators += '#ifdef %s\n' % cur_cmd.protect
 
                 terminators += mod_string
                 terminators += '\n'
 
-                if (cur_cmd.protect != None):
+                if (cur_cmd.protect is not None):
                     terminators += '#endif // %s\n' % cur_cmd.protect
 
         terminators += '\n'
@@ -960,7 +960,7 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                     physdev_type_to_replace = 'VkPhysicalDevice'
                     physdev_name_replacement = 'phys_dev_term->phys_dev'
 
-            if (ext_cmd.return_type != None):
+            if (ext_cmd.return_type is not None):
                 return_prefix += 'return '
                 has_return_type = True
 
@@ -1041,7 +1041,7 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                     count += 1
                 funcs += ');\n'
                 if ext_cmd.ext_name in NULL_CHECK_EXT_NAMES:
-                    if ext_cmd.return_type != None:
+                    if ext_cmd.return_type is not None:
                         funcs += '    } else {\n'
                         funcs += '        return VK_SUCCESS;\n'
                     funcs += '    }\n'
@@ -1273,7 +1273,7 @@ class LoaderExtensionOutputGenerator(OutputGenerator):
                     count += 1
                 funcs += ');\n'
                 if ext_cmd.ext_name in NULL_CHECK_EXT_NAMES:
-                    if ext_cmd.return_type != None:
+                    if ext_cmd.return_type is not None:
                         funcs += '    } else {\n'
                         funcs += '        return VK_SUCCESS;\n'
                     funcs += '    }\n'
index ab0ce8a2ab83d9050fb9f1f4035989564b7cfec5..3ef6f8fc70d82fb4c14723359a0b2ece266a5578 100644 (file)
@@ -32,7 +32,7 @@ def endTimer(timeit, msg):
 
 # Turn a list of strings into a regexp string matching exactly those strings
 def makeREstring(list, default = None):
-    if len(list) > 0 or default == None:
+    if len(list) > 0 or default is None:
         return '^(' + '|'.join(list) + ')$'
     else:
         return default