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

Skip to content

Commit b0002d2

Browse files
committed
Rename ifilterfalse() to filterfalse() and izip_longest() to zip_longest().
1 parent a6c6037 commit b0002d2

4 files changed

Lines changed: 93 additions & 93 deletions

File tree

Doc/library/itertools.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ loops that truncate the stream.
233233
self.currkey = self.keyfunc(self.currvalue)
234234

235235

236-
.. function:: ifilterfalse(predicate, iterable)
236+
.. function:: filterfalse(predicate, iterable)
237237

238238
Make an iterator that filters elements from iterable returning only those for
239239
which the predicate is ``False``. If *predicate* is ``None``, return the items
240240
that are false. Equivalent to::
241241

242-
def ifilterfalse(predicate, iterable):
242+
def filterfalse(predicate, iterable):
243243
if predicate is None:
244244
predicate = bool
245245
for x in iterable:
@@ -292,16 +292,16 @@ loops that truncate the stream.
292292

293293
:func:`izip` should only be used with unequal length inputs when you don't
294294
care about trailing, unmatched values from the longer iterables. If those
295-
values are important, use :func:`izip_longest` instead.
295+
values are important, use :func:`zip_longest` instead.
296296

297297

298-
.. function:: izip_longest(*iterables[, fillvalue])
298+
.. function:: zip_longest(*iterables[, fillvalue])
299299

300300
Make an iterator that aggregates elements from each of the iterables. If the
301301
iterables are of uneven length, missing values are filled-in with *fillvalue*.
302302
Iteration continues until the longest iterable is exhausted. Equivalent to::
303303

304-
def izip_longest(*args, **kwds):
304+
def zip_longest(*args, **kwds):
305305
fillvalue = kwds.get('fillvalue')
306306
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
307307
yield counter() # yields the fillvalue, or raises IndexError
@@ -313,7 +313,7 @@ loops that truncate the stream.
313313
except IndexError:
314314
pass
315315

316-
If one of the iterables is potentially infinite, then the :func:`izip_longest`
316+
If one of the iterables is potentially infinite, then the :func:`zip_longest`
317317
function should be wrapped with something that limits the number of calls (for
318318
example :func:`islice` or :func:`takewhile`).
319319

@@ -568,7 +568,7 @@ which incur interpreter overhead. ::
568568

569569
def all(seq, pred=None):
570570
"Returns True if pred(x) is true for every element in the iterable"
571-
for elem in ifilterfalse(pred, seq):
571+
for elem in filterfalse(pred, seq):
572572
return False
573573
return True
574574

Lib/filecmp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
import stat
1414
import warnings
15-
from itertools import ifilterfalse, izip
15+
from itertools import filterfalse, izip
1616

1717
__all__ = ["cmp","dircmp","cmpfiles"]
1818

@@ -133,8 +133,8 @@ def phase1(self): # Compute common names
133133
a = dict(izip(map(os.path.normcase, self.left_list), self.left_list))
134134
b = dict(izip(map(os.path.normcase, self.right_list), self.right_list))
135135
self.common = list(map(a.__getitem__, filter(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)))
136+
self.left_only = list(map(a.__getitem__, filterfalse(b.__contains__, a)))
137+
self.right_only = list(map(b.__getitem__, filterfalse(a.__contains__, b)))
138138

139139
def phase2(self): # Distinguish files, directories, funnies
140140
self.common_dirs = []
@@ -276,7 +276,7 @@ def _cmp(a, b, sh, abs=abs, cmp=cmp):
276276
# Return a copy with items that occur in skip removed.
277277
#
278278
def _filter(flist, skip):
279-
return list(ifilterfalse(skip.__contains__, flist))
279+
return list(filterfalse(skip.__contains__, flist))
280280

281281

282282
# Demonstration and testing.

Lib/test/test_itertools.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ def test_ifilter(self):
324324
self.assertRaises(TypeError, ifilter, isEven, 3)
325325
self.assertRaises(TypeError, next, ifilter(range(6), range(6)))
326326

327-
def test_ifilterfalse(self):
328-
self.assertEqual(list(ifilterfalse(isEven, range(6))), [1,3,5])
329-
self.assertEqual(list(ifilterfalse(None, [0,1,0,2,0])), [0,0,0])
330-
self.assertEqual(list(ifilterfalse(bool, [0,1,0,2,0])), [0,0,0])
331-
self.assertEqual(take(4, ifilterfalse(isEven, count())), [1,3,5,7])
332-
self.assertRaises(TypeError, ifilterfalse)
333-
self.assertRaises(TypeError, ifilterfalse, lambda x:x)
334-
self.assertRaises(TypeError, ifilterfalse, lambda x:x, range(6), 7)
335-
self.assertRaises(TypeError, ifilterfalse, isEven, 3)
336-
self.assertRaises(TypeError, next, ifilterfalse(range(6), range(6)))
327+
def test_filterfalse(self):
328+
self.assertEqual(list(filterfalse(isEven, range(6))), [1,3,5])
329+
self.assertEqual(list(filterfalse(None, [0,1,0,2,0])), [0,0,0])
330+
self.assertEqual(list(filterfalse(bool, [0,1,0,2,0])), [0,0,0])
331+
self.assertEqual(take(4, filterfalse(isEven, count())), [1,3,5,7])
332+
self.assertRaises(TypeError, filterfalse)
333+
self.assertRaises(TypeError, filterfalse, lambda x:x)
334+
self.assertRaises(TypeError, filterfalse, lambda x:x, range(6), 7)
335+
self.assertRaises(TypeError, filterfalse, isEven, 3)
336+
self.assertRaises(TypeError, next, filterfalse(range(6), range(6)))
337337

338338
def test_izip(self):
339339
# XXX This is rather silly now that builtin zip() calls izip()...
@@ -366,25 +366,25 @@ def test_iziplongest(self):
366366
]:
367367
target = [tuple([arg[i] if i < len(arg) else None for arg in args])
368368
for i in range(max(map(len, args)))]
369-
self.assertEqual(list(izip_longest(*args)), target)
370-
self.assertEqual(list(izip_longest(*args, **{})), target)
369+
self.assertEqual(list(zip_longest(*args)), target)
370+
self.assertEqual(list(zip_longest(*args, **{})), target)
371371
target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X'
372-
self.assertEqual(list(izip_longest(*args, **dict(fillvalue='X'))), target)
372+
self.assertEqual(list(zip_longest(*args, **dict(fillvalue='X'))), target)
373373

374-
self.assertEqual(take(3,izip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
374+
self.assertEqual(take(3,zip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
375375

376-
self.assertEqual(list(izip_longest()), list(zip()))
377-
self.assertEqual(list(izip_longest([])), list(zip([])))
378-
self.assertEqual(list(izip_longest('abcdef')), list(zip('abcdef')))
376+
self.assertEqual(list(zip_longest()), list(zip()))
377+
self.assertEqual(list(zip_longest([])), list(zip([])))
378+
self.assertEqual(list(zip_longest('abcdef')), list(zip('abcdef')))
379379

380-
self.assertEqual(list(izip_longest('abc', 'defg', **{})),
380+
self.assertEqual(list(zip_longest('abc', 'defg', **{})),
381381
list(izip(list('abc')+[None], 'defg'))) # empty keyword dict
382-
self.assertRaises(TypeError, izip_longest, 3)
383-
self.assertRaises(TypeError, izip_longest, range(3), 3)
382+
self.assertRaises(TypeError, zip_longest, 3)
383+
self.assertRaises(TypeError, zip_longest, range(3), 3)
384384

385385
for stmt in [
386-
"izip_longest('abc', fv=1)",
387-
"izip_longest('abc', fillvalue=1, bogus_keyword=None)",
386+
"zip_longest('abc', fv=1)",
387+
"zip_longest('abc', fillvalue=1, bogus_keyword=None)",
388388
]:
389389
try:
390390
eval(stmt, globals(), locals())
@@ -394,13 +394,13 @@ def test_iziplongest(self):
394394
self.fail('Did not raise Type in: ' + stmt)
395395

396396
# Check tuple re-use (implementation detail)
397-
self.assertEqual([tuple(list(pair)) for pair in izip_longest('abc', 'def')],
397+
self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')],
398398
list(zip('abc', 'def')))
399-
self.assertEqual([pair for pair in izip_longest('abc', 'def')],
399+
self.assertEqual([pair for pair in zip_longest('abc', 'def')],
400400
list(zip('abc', 'def')))
401-
ids = list(map(id, izip_longest('abc', 'def')))
401+
ids = list(map(id, zip_longest('abc', 'def')))
402402
self.assertEqual(min(ids), max(ids))
403-
ids = list(map(id, list(izip_longest('abc', 'def'))))
403+
ids = list(map(id, list(zip_longest('abc', 'def'))))
404404
self.assertEqual(len(dict.fromkeys(ids)), len(ids))
405405

406406
def test_product(self):
@@ -659,7 +659,7 @@ def test_StopIteration(self):
659659

660660
self.assertRaises(StopIteration, next, repeat(None, 0))
661661

662-
for f in (ifilter, ifilterfalse, imap, takewhile, dropwhile, starmap):
662+
for f in (ifilter, filterfalse, imap, takewhile, dropwhile, starmap):
663663
self.assertRaises(StopIteration, next, f(lambda x:x, []))
664664
self.assertRaises(StopIteration, next, f(lambda x:x, StopNow()))
665665

@@ -690,9 +690,9 @@ def test_ifilter(self):
690690
a = []
691691
self.makecycle(ifilter(lambda x:True, [a]*2), a)
692692

693-
def test_ifilterfalse(self):
693+
def test_filterfalse(self):
694694
a = []
695-
self.makecycle(ifilterfalse(lambda x:False, a), a)
695+
self.makecycle(filterfalse(lambda x:False, a), a)
696696

697697
def test_izip(self):
698698
a = []
@@ -840,14 +840,14 @@ def test_ifilter(self):
840840
self.assertRaises(TypeError, ifilter, isEven, N(s))
841841
self.assertRaises(ZeroDivisionError, list, ifilter(isEven, E(s)))
842842

843-
def test_ifilterfalse(self):
843+
def test_filterfalse(self):
844844
for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
845845
for g in (G, I, Ig, S, L, R):
846-
self.assertEqual(list(ifilterfalse(isEven, g(s))),
846+
self.assertEqual(list(filterfalse(isEven, g(s))),
847847
[x for x in g(s) if isOdd(x)])
848-
self.assertRaises(TypeError, ifilterfalse, isEven, X(s))
849-
self.assertRaises(TypeError, ifilterfalse, isEven, N(s))
850-
self.assertRaises(ZeroDivisionError, list, ifilterfalse(isEven, E(s)))
848+
self.assertRaises(TypeError, filterfalse, isEven, X(s))
849+
self.assertRaises(TypeError, filterfalse, isEven, N(s))
850+
self.assertRaises(ZeroDivisionError, list, filterfalse(isEven, E(s)))
851851

852852
def test_izip(self):
853853
for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
@@ -861,11 +861,11 @@ def test_izip(self):
861861
def test_iziplongest(self):
862862
for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
863863
for g in (G, I, Ig, S, L, R):
864-
self.assertEqual(list(izip_longest(g(s))), list(zip(g(s))))
865-
self.assertEqual(list(izip_longest(g(s), g(s))), list(zip(g(s), g(s))))
866-
self.assertRaises(TypeError, izip_longest, X(s))
867-
self.assertRaises(TypeError, izip_longest, N(s))
868-
self.assertRaises(ZeroDivisionError, list, izip_longest(E(s)))
864+
self.assertEqual(list(zip_longest(g(s))), list(zip(g(s))))
865+
self.assertEqual(list(zip_longest(g(s), g(s))), list(zip(g(s), g(s))))
866+
self.assertRaises(TypeError, zip_longest, X(s))
867+
self.assertRaises(TypeError, zip_longest, N(s))
868+
self.assertRaises(ZeroDivisionError, list, zip_longest(E(s)))
869869

870870
def test_imap(self):
871871
for s in (range(10), range(0), range(100), (7,11), range(20,50,5)):
@@ -1001,7 +1001,7 @@ def gen2(x):
10011001
class SubclassWithKwargsTest(unittest.TestCase):
10021002
def test_keywords_in_subclass(self):
10031003
# count is not subclassable...
1004-
for cls in (repeat, izip, ifilter, ifilterfalse, chain, imap,
1004+
for cls in (repeat, izip, ifilter, filterfalse, chain, imap,
10051005
starmap, islice, takewhile, dropwhile, cycle):
10061006
class Subclass(cls):
10071007
def __init__(self, newarg=None, *args):
@@ -1085,7 +1085,7 @@ def __init__(self, newarg=None, *args):
10851085
10861086
>>> def all(seq, pred=None):
10871087
... "Returns True if pred(x) is true for every element in the iterable"
1088-
... for elem in ifilterfalse(pred, seq):
1088+
... for elem in filterfalse(pred, seq):
10891089
... return False
10901090
... return True
10911091

0 commit comments

Comments
 (0)