X Tutup
Skip to content

Commit c1f779c

Browse files
committed
Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines Fix a place where floor division would be in order. ........ r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines Make map() and filter() identical to itertools.imap() and .ifilter(), respectively. I fixed two bootstrap issues, due to the dynamic import of itertools: 1. Starting python requires that map() and filter() are not used until site.py has added build/lib.<arch> to sys.path. 2. Building python requires that setup.py and distutils and everything they use is free of map() and filter() calls. Beyond this, I only fixed the tests in test_builtin.py. Others, please help fixing the remaining tests that are now broken! The fixes are usually simple: a. map(None, X) -> list(X) b. map(F, X) -> list(map(F, X)) c. map(lambda x: F(x), X) -> [F(x) for x in X] d. filter(F, X) -> list(filter(F, X)) e. filter(lambda x: P(x), X) -> [x for x in X if P(x)] Someone, please also contribute a fixer for 2to3 to do this. It can leave map()/filter() calls alone that are already inside a list() or sorted() call or for-loop. Only in rare cases have I seen code that depends on map() of lists of different lengths going to the end of the longest, or on filter() of a string or tuple returning an object of the same type; these will need more thought to fix. ........ r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines Make it so that test_decimal fails instead of hangs, to help automated test runners. ........ r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines Fix a few test cases after the map->imap change. ........ r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line Get a bunch more tests passing after converting map/filter to return iterators. ........ r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines Fix the remaining failing unit tests (at least on OSX). Also tweaked urllib2 so it doesn't raise socket.gaierror when all network interfaces are turned off. ........
1 parent d094130 commit c1f779c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+229
-758
lines changed

Lib/cgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def getvalue(self, key, default=None):
572572
if key in self:
573573
value = self[key]
574574
if type(value) is type([]):
575-
return map(attrgetter('value'), value)
575+
return [x.value for x in value]
576576
else:
577577
return value.value
578578
else:
@@ -594,7 +594,7 @@ def getlist(self, key):
594594
if key in self:
595595
value = self[key]
596596
if type(value) is type([]):
597-
return map(attrgetter('value'), value)
597+
return [x.value for x in value]
598598
else:
599599
return [value.value]
600600
else:

Lib/csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _guess_delimiter(self, data, delimiters):
253253
additional chunks as necessary.
254254
"""
255255

256-
data = filter(None, data.split('\n'))
256+
data = list(filter(None, data.split('\n')))
257257

258258
ascii = [chr(c) for c in range(127)] # 7-bit ASCII
259259

Lib/decimal.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ def __str__(self, eng = 0, context=None):
841841
if context is None:
842842
context = getcontext()
843843

844-
tmp = map(str, self._int)
844+
tmp = list(map(str, self._int))
845845
numdigits = len(self._int)
846846
leftdigits = self._exp + numdigits
847847
if eng and not self: # self = 0eX wants 0[.0[0]]eY, not [[0]0]0eY
@@ -1193,7 +1193,9 @@ def __mul__(self, other, context=None):
11931193
op1 = _WorkRep(self)
11941194
op2 = _WorkRep(other)
11951195

1196-
ans = Decimal((resultsign, map(int, str(op1.int * op2.int)), resultexp))
1196+
ans = Decimal((resultsign,
1197+
tuple(map(int, str(op1.int * op2.int))),
1198+
resultexp))
11971199
if shouldround:
11981200
ans = ans._fix(context)
11991201

@@ -3145,7 +3147,7 @@ def _string2exact(s):
31453147
exp -= len(fracpart)
31463148

31473149
mantissa = intpart + fracpart
3148-
tmp = map(int, mantissa)
3150+
tmp = list(map(int, mantissa))
31493151
backup = tmp
31503152
while tmp and tmp[0] == 0:
31513153
del tmp[0]

Lib/difflib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def get_grouped_opcodes(self, n=3):
587587
Each group is in the same format as returned by get_opcodes().
588588
589589
>>> from pprint import pprint
590-
>>> a = map(str, range(1,40))
590+
>>> a = list(map(str, range(1,40)))
591591
>>> b = a[:]
592592
>>> b[8:8] = ['i'] # Make an insertion
593593
>>> b[20] += 'x' # Make a replacement

Lib/distutils/dist.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ class Distribution:
112112
('obsoletes', None,
113113
"print the list of packages/modules made obsolete")
114114
]
115-
display_option_names = map(lambda x: translate_longopt(x[0]),
116-
display_options)
115+
display_option_names = [translate_longopt(x[0]) for x in display_options]
117116

118117
# negative options are options that exclude other options
119118
negative_opt = {'quiet': 'verbose'}
@@ -805,7 +804,7 @@ def get_command_packages (self):
805804
pkgs = (pkgs or "").split(",")
806805
for i in range(len(pkgs)):
807806
pkgs[i] = pkgs[i].strip()
808-
pkgs = filter(None, pkgs)
807+
pkgs = [p for p in pkgs if p]
809808
if "distutils.command" not in pkgs:
810809
pkgs.insert(0, "distutils.command")
811810
self.command_packages = pkgs

Lib/distutils/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def _init_posix():
372372
if cur_target == '':
373373
cur_target = cfg_target
374374
os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
375-
elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
375+
elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
376376
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
377377
% (cur_target, cfg_target))
378378
raise DistutilsPlatformError(my_msg)

Lib/distutils/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def parse (self, vstring):
148148
if patch:
149149
self.version = tuple(map(int, [major, minor, patch]))
150150
else:
151-
self.version = tuple(map(int, [major, minor]) + [0])
151+
self.version = tuple(map(int, [major, minor])) + (0,)
152152

153153
if prerelease:
154154
self.prerelease = (prerelease[0], int(prerelease_num))

Lib/encodings/idna.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def nameprep(label):
3838
raise UnicodeError("Invalid character %r" % c)
3939

4040
# Check bidi
41-
RandAL = map(stringprep.in_table_d1, label)
41+
RandAL = [stringprep.in_table_d1(x) for x in label]
4242
for c in RandAL:
4343
if c:
4444
# There is a RandAL char in the string. Must perform further
@@ -47,7 +47,7 @@ def nameprep(label):
4747
# This is table C.8, which was already checked
4848
# 2) If a string contains any RandALCat character, the string
4949
# MUST NOT contain any LCat character.
50-
if filter(stringprep.in_table_d2, label):
50+
if any(stringprep.in_table_d2(x) for x in label):
5151
raise UnicodeError("Violation of BIDI requirement 2")
5252

5353
# 3) If a string contains any RandALCat character, a

Lib/filecmp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def phase0(self): # Compare everything except common subdirectories
132132
def phase1(self): # Compute common names
133133
a = dict(izip(imap(os.path.normcase, self.left_list), self.left_list))
134134
b = dict(izip(imap(os.path.normcase, self.right_list), self.right_list))
135-
self.common = map(a.__getitem__, ifilter(b.__contains__, a))
136-
self.left_only = map(a.__getitem__, ifilterfalse(b.__contains__, a))
137-
self.right_only = map(b.__getitem__, ifilterfalse(a.__contains__, b))
135+
self.common = list(map(a.__getitem__, ifilter(b.__contains__, a)))
136+
self.left_only = list(map(a.__getitem__, ifilterfalse(b.__contains__, a)))
137+
self.right_only = list(map(b.__getitem__, ifilterfalse(a.__contains__, b)))
138138

139139
def phase2(self): # Distinguish files, directories, funnies
140140
self.common_dirs = []

Lib/heapq.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
__all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
130130
'nlargest', 'nsmallest']
131131

132-
from itertools import islice, repeat, count, imap, izip, tee
132+
from itertools import islice, repeat, count, izip, tee
133133
from operator import itemgetter, neg
134134
import bisect
135135

@@ -225,7 +225,7 @@ def nsmallest(n, iterable):
225225
# O(m) + O(n log m) comparisons.
226226
h = list(iterable)
227227
heapify(h)
228-
return map(heappop, repeat(h, min(n, len(h))))
228+
return list(map(heappop, repeat(h, min(n, len(h)))))
229229

230230
# 'heap' is a heap at all indices >= startpos, except possibly for pos. pos
231231
# is the index of a leaf with a possibly out-of-order value. Restore the
@@ -351,9 +351,9 @@ def nsmallest(n, iterable, key=None):
351351
Equivalent to: sorted(iterable, key=key)[:n]
352352
"""
353353
in1, in2 = tee(iterable)
354-
it = izip(imap(key, in1), count(), in2) # decorate
354+
it = izip(map(key, in1), count(), in2) # decorate
355355
result = _nsmallest(n, it)
356-
return map(itemgetter(2), result) # undecorate
356+
return list(map(itemgetter(2), result)) # undecorate
357357

358358
_nlargest = nlargest
359359
def nlargest(n, iterable, key=None):
@@ -362,9 +362,9 @@ def nlargest(n, iterable, key=None):
362362
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
363363
"""
364364
in1, in2 = tee(iterable)
365-
it = izip(imap(key, in1), imap(neg, count()), in2) # decorate
365+
it = izip(map(key, in1), map(neg, count()), in2) # decorate
366366
result = _nlargest(n, it)
367-
return map(itemgetter(2), result) # undecorate
367+
return list(map(itemgetter(2), result)) # undecorate
368368

369369
if __name__ == "__main__":
370370
# Simple sanity test

0 commit comments

Comments
 (0)
X Tutup