Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b59f5f

Browse files
committed
Let library modules use the new keyword arguments for list.sort().
1 parent 42b1ba3 commit 6b59f5f

7 files changed

Lines changed: 18 additions & 24 deletions

File tree

Lib/SimpleHTTPServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def list_directory(self, path):
9999
except os.error:
100100
self.send_error(404, "No permission to list directory")
101101
return None
102-
list.sort(lambda a, b: cmp(a.lower(), b.lower()))
102+
list.sort(key=lambda a: a.lower())
103103
f = StringIO()
104104
f.write("<title>Directory listing for %s</title>\n" % self.path)
105105
f.write("<h2>Directory listing for %s</h2>\n" % self.path)

Lib/UserList.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def remove(self, item): self.data.remove(item)
7777
def count(self, item): return self.data.count(item)
7878
def index(self, item, *args): return self.data.index(item, *args)
7979
def reverse(self): self.data.reverse()
80-
def sort(self, *args): self.data.sort(*args)
80+
def sort(self, *args, **kwds): self.data.sort(*args, **kwds)
8181
def extend(self, other):
8282
if isinstance(other, UserList):
8383
self.data.extend(other.data)

Lib/_strptime.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LocaleTime(object):
5252

5353
def __init__(self):
5454
"""Set all attributes.
55-
55+
5656
Order of methods called matters for dependency reasons.
5757
5858
The locale language is set at the offset and then checked again before
@@ -68,7 +68,7 @@ def __init__(self):
6868
Only other possible issue is if someone changed the timezone and did
6969
not call tz.tzset . That is an issue for the programmer, though,
7070
since changing the timezone is worthless without that call.
71-
71+
7272
"""
7373
self.lang = _getlang()
7474
self.__calc_weekday()
@@ -155,7 +155,7 @@ def __calc_date_time(self):
155155
date_time[offset] = current_format.replace('11', U_W)
156156
self.LC_date_time = date_time[0]
157157
self.LC_date = date_time[1]
158-
self.LC_time = date_time[2]
158+
self.LC_time = date_time[2]
159159

160160
def __calc_timezone(self):
161161
# Set self.timezone by using time.tzname.
@@ -178,9 +178,9 @@ class TimeRE(dict):
178178

179179
def __init__(self, locale_time=None):
180180
"""Create keys/values.
181-
181+
182182
Order of execution is important for dependency reasons.
183-
183+
184184
"""
185185
if locale_time:
186186
self.locale_time = locale_time
@@ -219,22 +219,20 @@ def __init__(self, locale_time=None):
219219

220220
def __seqToRE(self, to_convert, directive):
221221
"""Convert a list to a regex string for matching a directive.
222-
222+
223223
Want possible matching values to be from longest to shortest. This
224224
prevents the possibility of a match occuring for a value that also
225225
a substring of a larger value that should have matched (e.g., 'abc'
226226
matching when 'abcdef' should have been the match).
227-
227+
228228
"""
229229
for value in to_convert:
230230
if value != '':
231231
break
232232
else:
233233
return ''
234-
to_sort = [(len(item), item) for item in to_convert]
235-
to_sort.sort()
236-
to_sort.reverse()
237-
to_convert = [item for length, item in to_sort]
234+
to_convert = to_convert[:]
235+
to_convert.sort(key=len, reverse=True)
238236
regex = '|'.join(to_convert)
239237
regex = '(?P<%s>%s' % (directive, regex)
240238
return '%s)' % regex

Lib/difflib.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,11 @@ def get_close_matches(word, possibilities, n=3, cutoff=0.6):
701701
s.quick_ratio() >= cutoff and \
702702
s.ratio() >= cutoff:
703703
result.append((s.ratio(), x))
704-
# Sort by score.
705-
result.sort()
706-
# Retain only the best n.
707-
result = result[-n:]
708-
# Move best-scorer to head of list.
709-
result.reverse()
710-
# Strip scores.
711-
return [x for score, x in result]
712704

705+
# Move the best scorers to head of list
706+
result.sort(reverse=True)
707+
# Strip scores for the best n matches
708+
return [x for score, x in result[:n]]
713709

714710
def _count_leading(line, ch):
715711
"""

Lib/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ def getsource(object):
553553
def walktree(classes, children, parent):
554554
"""Recursive helper function for getclasstree()."""
555555
results = []
556-
classes.sort(lambda a, b: cmp(a.__name__, b.__name__))
556+
classes.sort(key=lambda c: c.__name__)
557557
for c in classes:
558558
results.append((c, c.__bases__))
559559
if c in children:

Lib/pydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ def spilldata(msg, attrs, predicate):
779779
tag += ':<br>\n'
780780

781781
# Sort attrs by name.
782-
attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))
782+
attrs.sort(key=lambda t: t[0])
783783

784784
# Pump out the attrs, segregated by kind.
785785
attrs = spill('Methods %s' % tag, attrs,

Lib/sre_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def makedict(list):
219219
import string
220220
def dump(f, d, prefix):
221221
items = d.items()
222-
items.sort(lambda a, b: cmp(a[1], b[1]))
222+
items.sort(key=lambda a: a[1])
223223
for k, v in items:
224224
f.write("#define %s_%s %s\n" % (prefix, string.upper(k), v))
225225
f = open("sre_constants.h", "w")

0 commit comments

Comments
 (0)