]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Replace cmp function with key function
authorÉric Araujo <merwok@netwok.org>
Sun, 18 Sep 2011 19:03:24 +0000 (21:03 +0200)
committerÉric Araujo <merwok@netwok.org>
Sun, 18 Sep 2011 19:03:24 +0000 (21:03 +0200)
Lib/packaging/create.py

index ecabca041a358cea70588d4c097908d0109c2cea..1e84e2e547021106a23cc06c40d9e861f38080b4 100644 (file)
@@ -28,7 +28,6 @@ import sysconfig
 import tokenize
 from hashlib import md5
 from textwrap import dedent
-from functools import cmp_to_key
 from configparser import RawConfigParser
 # importing this with an underscore as it should be replaced by the
 # dict form or another structures for all purposes
@@ -370,21 +369,9 @@ class MainProgram:
                     dist.data_files = [('', dist.data_files)]
                 # add tokens in the destination paths
                 vars = {'distribution.name': data['name']}
-                path_tokens = list(sysconfig.get_paths(vars=vars).items())
-
-                # TODO replace this with a key function
-                def length_comparison(x, y):
-                    len_x = len(x[1])
-                    len_y = len(y[1])
-                    if len_x == len_y:
-                        return 0
-                    elif len_x < len_y:
-                        return -1
-                    else:
-                        return 1
-
+                path_tokens = sysconfig.get_paths(vars=vars).items()
                 # sort tokens to use the longest one first
-                path_tokens.sort(key=cmp_to_key(length_comparison))
+                path_tokens = sorted(path_tokens, key=lambda x: len(x[1]))
                 for dest, srcs in (dist.data_files or []):
                     dest = os.path.join(sys.prefix, dest)
                     dest = dest.replace(os.path.sep, '/')