[PATCH v2 6/8] python3: Replace keys() + sort() with sorted()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The keys() method no longer returns a list, so converting the
return value would be necessary before calling sort() on it;
alternatively, we can just call sorted(), which returns a
sorted list.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 docs/apibuild.py                   | 60 +++++++++++++-------------------------
 src/esx/esx_vi_generator.py        | 15 ++++------
 src/hyperv/hyperv_wmi_generator.py |  3 +-
 3 files changed, 26 insertions(+), 52 deletions(-)

diff --git a/docs/apibuild.py b/docs/apibuild.py
index bc6c609431..67b7eed1e6 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -133,8 +133,7 @@ def uniq(items):
     d = {}
     for item in items:
         d[item]=1
-    k = d.keys()
-    k.sort()
+    k = sorted(d.keys())
     return k
 
 class identifier:
@@ -2337,8 +2336,7 @@ class docBuilder:
                 if desc.find("DEPRECATED") != -1:
                     output.write("     <deprecated/>\n")
 
-        ids = dict.macros.keys()
-        ids.sort()
+        ids = sorted(dict.macros.keys())
         for id in uniq(ids):
             # Macros are sometime used to masquerade other types.
             if id in dict.functions:
@@ -2354,31 +2352,25 @@ class docBuilder:
             if id in dict.enums:
                 continue
             output.write("     <exports symbol='%s' type='macro'/>\n" % (id))
-        ids = dict.enums.keys()
-        ids.sort()
+        ids = sorted(dict.enums.keys())
         for id in uniq(ids):
             output.write("     <exports symbol='%s' type='enum'/>\n" % (id))
-        ids = dict.typedefs.keys()
-        ids.sort()
+        ids = sorted(dict.typedefs.keys())
         for id in uniq(ids):
             output.write("     <exports symbol='%s' type='typedef'/>\n" % (id))
-        ids = dict.structs.keys()
-        ids.sort()
+        ids = sorted(dict.structs.keys())
         for id in uniq(ids):
             output.write("     <exports symbol='%s' type='struct'/>\n" % (id))
-        ids = dict.variables.keys()
-        ids.sort()
+        ids = sorted(dict.variables.keys())
         for id in uniq(ids):
             output.write("     <exports symbol='%s' type='variable'/>\n" % (id))
-        ids = dict.functions.keys()
-        ids.sort()
+        ids = sorted(dict.functions.keys())
         for id in uniq(ids):
             output.write("     <exports symbol='%s' type='function'/>\n" % (id))
         output.write("    </file>\n")
 
     def serialize_xrefs_files(self, output):
-        headers = self.headers.keys()
-        headers.sort()
+        headers = sorted(self.headers.keys())
         for file in headers:
             module = self.modulename_file(file)
             output.write("    <file name='%s'>\n" % (module))
@@ -2410,8 +2402,7 @@ class docBuilder:
                         funcs[param[0]] = [name]
             except:
                 pass
-        typ = funcs.keys()
-        typ.sort()
+        typ = sorted(funcs.keys())
         for type in typ:
             if type == '' or type == 'void' or type == "int" or \
                type == "char *" or type == "const char *" :
@@ -2440,23 +2431,20 @@ class docBuilder:
                     funcs[ret[0]] = [name]
             except:
                 pass
-        typ = funcs.keys()
-        typ.sort()
+        typ = sorted(funcs.keys())
         for type in typ:
             if type == '' or type == 'void' or type == "int" or \
                type == "char *" or type == "const char *" :
                 continue
             output.write("    <type name='%s'>\n" % (type))
-            ids = funcs[type]
-            ids.sort()
+            ids = sorted(funcs[type])
             for id in ids:
                 output.write("      <ref name='%s'/>\n" % (id))
             output.write("    </type>\n")
 
     def serialize_xrefs_alpha(self, output):
         letter = None
-        ids = self.idx.identifiers.keys()
-        ids.sort()
+        ids = sorted(self.idx.identifiers.keys())
         for id in ids:
             if id[0] != letter:
                 if letter is not None:
@@ -2468,8 +2456,7 @@ class docBuilder:
             output.write("    </letter>\n")
 
     def serialize_xrefs_references(self, output):
-        typ = self.idx.identifiers.keys()
-        typ.sort()
+        typ = sorted(self.idx.identifiers.keys())
         for id in typ:
             idf = self.idx.identifiers[id]
             module = idf.header
@@ -2480,8 +2467,7 @@ class docBuilder:
 
     def serialize_xrefs_index(self, output):
         index = self.xref
-        typ = index.keys()
-        typ.sort()
+        typ = sorted(index.keys())
         letter = None
         count = 0
         chunk = 0
@@ -2553,30 +2539,24 @@ class docBuilder:
         output.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n')
         output.write("<api name='%s'>\n" % self.name)
         output.write("  <files>\n")
-        headers = self.headers.keys()
-        headers.sort()
+        headers = sorted(self.headers.keys())
         for file in headers:
             self.serialize_exports(output, file)
         output.write("  </files>\n")
         output.write("  <symbols>\n")
-        macros = self.idx.macros.keys()
-        macros.sort()
+        macros = sorted(self.idx.macros.keys())
         for macro in macros:
             self.serialize_macro(output, macro)
-        enums = self.idx.enums.keys()
-        enums.sort()
+        enums = sorted(self.idx.enums.keys())
         for enum in enums:
             self.serialize_enum(output, enum)
-        typedefs = self.idx.typedefs.keys()
-        typedefs.sort()
+        typedefs = sorted(self.idx.typedefs.keys())
         for typedef in typedefs:
             self.serialize_typedef(output, typedef)
-        variables = self.idx.variables.keys()
-        variables.sort()
+        variables = sorted(self.idx.variables.keys())
         for variable in variables:
             self.serialize_variable(output, variable)
-        functions = self.idx.functions.keys()
-        functions.sort()
+        functions = sorted(self.idx.functions.keys())
         for function in functions:
             self.serialize_function(output, function)
         output.write("  </symbols>\n")
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index d7e68f69b1..2f3c88812d 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -1704,8 +1704,7 @@ types_typedef.write(separator +
                     " * VI Enums\n" +
                     " */\n\n")
 
-names = enums_by_name.keys()
-names.sort()
+names = sorted(enums_by_name.keys())
 
 for name in names:
     types_typedef.write(enums_by_name[name].generate_typedef())
@@ -1726,8 +1725,7 @@ types_typeenum.write("\n")
 types_typetostring.write("\n")
 types_typefromstring.write("\n")
 
-names = objects_by_name.keys()
-names.sort()
+names = sorted(objects_by_name.keys())
 
 for name in names:
     types_typedef.write(objects_by_name[name].generate_typedef())
@@ -1748,8 +1746,7 @@ types_typeenum.write("\n")
 types_typetostring.write("\n")
 types_typefromstring.write("\n")
 
-names = managed_objects_by_name.keys()
-names.sort()
+names = sorted(managed_objects_by_name.keys())
 
 for name in names:
     types_typedef.write(managed_objects_by_name[name].generate_typedef())
@@ -1762,8 +1759,7 @@ for name in names:
 
 
 # output methods
-names = methods_by_name.keys()
-names.sort()
+names = sorted(methods_by_name.keys())
 
 for name in names:
     methods_header.write(methods_by_name[name].generate_header())
@@ -1782,8 +1778,7 @@ for name in names:
 
 
 # output helpers
-names = managed_objects_by_name.keys()
-names.sort()
+names = sorted(managed_objects_by_name.keys())
 
 for name in names:
     helpers_header.write(managed_objects_by_name[name].generate_helper_header())
diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_generator.py
index f6e0523f32..1cf16a7836 100755
--- a/src/hyperv/hyperv_wmi_generator.py
+++ b/src/hyperv/hyperv_wmi_generator.py
@@ -501,8 +501,7 @@ def main():
     classes_header.write(notice)
     classes_source.write(notice)
 
-    names = wmi_classes_by_name.keys()
-    names.sort()
+    names = sorted(wmi_classes_by_name.keys())
 
     for name in names:
         cls = wmi_classes_by_name[name]
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux