[Python-checkins] cpython: Replace cmp function with key function

eric.araujo python-checkins at python.org
Mon Sep 19 16:10:54 CEST 2011


http://hg.python.org/cpython/rev/76ff72904de4
changeset: 72407:76ff72904de4
user: Éric Araujo <merwok at netwok.org>
date: Sun Sep 18 21:03:24 2011 +0200
summary:
 Replace cmp function with key function
files:
 Lib/packaging/create.py | 17 ++---------------
 1 files changed, 2 insertions(+), 15 deletions(-)
diff --git a/Lib/packaging/create.py b/Lib/packaging/create.py
--- a/Lib/packaging/create.py
+++ b/Lib/packaging/create.py
@@ -28,7 +28,6 @@
 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 @@
 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, '/')
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /