]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Python 3: do not use cmp(), nor sorted(..., cmp=...)
authorCyril Roelandt <cyril@redhat.com>
Wed, 17 Jun 2015 14:25:56 +0000 (14:25 +0000)
committerCyril Roelandt <cyril@redhat.com>
Wed, 17 Jun 2015 14:53:41 +0000 (16:53 +0200)
* The "cmp" function has been removed, so we must not use it any more;
* The "cmp" keyword argument of the "sorted" function has been removed, so
  replace it with "key=functool.cmp_to_key".

Change-Id: Ic39d29dc1002a68f36f04c32e53a36bc826dce78
Blueprint: neutron-python3

neutron/api/api_common.py

index e8a310247ae9d3a34c2e0c028f05199155c8f78a..7c062cd6d65c23de8b58a25defc54b4d0a90603a 100644 (file)
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import functools
 import urllib
 
 from oslo_config import cfg
@@ -272,11 +273,11 @@ class SortingEmulatedHelper(SortingHelper):
     def sort(self, items):
         def cmp_func(obj1, obj2):
             for key, direction in self.sort_dict:
-                ret = cmp(obj1[key], obj2[key])
+                ret = (obj1[key] > obj2[key]) - (obj1[key] < obj2[key])
                 if ret:
                     return ret * (1 if direction else -1)
             return 0
-        return sorted(items, cmp=cmp_func)
+        return sorted(items, key=functools.cmp_to_key(cmp_func))
 
 
 class SortingNativeHelper(SortingHelper):