Commits

masayuko committed e2a9d6f

Sort by key

  • Participants
  • Parent commits b0a796d

Comments (0)

Files changed (2)

File src/blockdiag/parser.py

         else:
             return 2
 
-    def keyfunction(item):
-        return weight(item)
-
     if hasattr(tree, 'stmts'):
-        tree.stmts.sort(key=keyfunction)
+        tree.stmts.sort(key=lambda x: weight(x))
         for stmt in tree.stmts:
             sort_tree(stmt)
 

File src/blockdiag/utils/rst/directives.py

 from blockdiag.utils import any
 from blockdiag.utils.bootstrap import detectfont
 from blockdiag.utils.rst.nodes import blockdiag
+from functools import cmp_to_key
 
 
 directive_options_default = dict(format='PNG',
     except (TypeError, ValueError):
         n2 = 65535
 
-    return cmp(n1, n2)
+    # cmp n1 and n2
+    if n1 < n2:
+        return -1
+    elif n1 == n2:
+        return 0
+    else:
+        return 1
 
 
 class BlockdiagDirectiveBase(rst.Directive):
         headers = [klass.attrname[n] for n in klass.desctable]
 
         descriptions = [n.to_desctable() for n in nodes if n.drawable]
-        descriptions.sort(cmp_node_number)
+        descriptions.sort(key=cmp_to_key(cmp_node_number))
 
         for i in reversed(range(len(headers))):
             if any(desc[i] for desc in descriptions):