[py3] Use sorted(key=...) instead of sorted(cmp=...)
authorjulien tayon <julien.tayon@logilab.fr>
Tue, 11 Jun 2019 09:07:24 +0200
changeset 12637 234ca3cbbb46
parent 12636 06faf72cf308
child 12638 8466a6dd474e
[py3] Use sorted(key=...) instead of sorted(cmp=...)
cubicweb/web/schemaviewer.py
--- a/cubicweb/web/schemaviewer.py	Fri Jun 07 14:56:22 2019 +0200
+++ b/cubicweb/web/schemaviewer.py	Tue Jun 11 09:07:24 2019 +0200
@@ -24,7 +24,7 @@
 
 from yams.schema2dot import CARD_MAP
 from yams.schema import RelationDefinitionSchema
-from operator import attrgetter
+from operator import attrgetter, itemgetter
 
 TYPE_GETTER = attrgetter('type')
 
@@ -89,7 +89,7 @@
             relations = [rschema for rschema in sorted(schema.relations(), key=TYPE_GETTER)
                          if not (rschema.final or rschema.type in skiptypes)]
             keys = [(rschema.type, rschema) for rschema in relations]
-            for key, rschema in sorted(keys, cmp=(lambda x, y: cmp(x[1], y[1]))):
+            for key, rschema in sorted(keys, key=itemgetter(1)):
                 relstr = self.visit_relationschema(rschema)
                 rsection.append(relstr)
         return layout
@@ -97,7 +97,8 @@
     def _entity_attributes_data(self, eschema):
         _ = self._
         data = [_('attribute'), _('type'), _('default'), _('constraints')]
-        attributes = sorted(eschema.attribute_definitions(), cmp=(lambda x, y: cmp(x[0].type, y[0].type)))
+        attributes = sorted(eschema.attribute_definitions(),
+                            key=lambda el: el[0].type)
         for rschema, aschema in attributes:
             rdef = eschema.rdef(rschema)
             if not self.may_read(rdef):
@@ -140,8 +141,8 @@
         first = True
 
         rel_defs = sorted(eschema.relation_definitions(),
-                          cmp=(lambda x, y: cmp((x[0].type, x[0].cardinality),
-                          (y[0].type, y[0].cardinality))))
+                          key=lambda el: (el[0].type, el[0].cardinality))
+
         for rschema, targetschemas, role in rel_defs:
             if rschema.type in skiptypes:
                 continue