| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a6c6037 commit b0002d2
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -233,13 +233,13 @@ loops that truncate the stream. | |||
| 233 | 233 | self.currkey = self.keyfunc(self.currvalue) | |
| 234 | 234 | ||
| 235 | 235 | ||
| 236 | - .. function:: ifilterfalse(predicate, iterable) | ||
| 236 | + .. function:: filterfalse(predicate, iterable) | ||
| 237 | 237 | ||
| 238 | 238 | Make an iterator that filters elements from iterable returning only those for | |
| 239 | 239 | which the predicate is ``False``. If *predicate* is ``None``, return the items | |
| 240 | 240 | that are false. Equivalent to:: | |
| 241 | 241 | ||
| 242 | - def ifilterfalse(predicate, iterable): | ||
| 242 | + def filterfalse(predicate, iterable): | ||
| 243 | 243 | if predicate is None: | |
| 244 | 244 | predicate = bool | |
| 245 | 245 | for x in iterable: | |
@@ -292,16 +292,16 @@ loops that truncate the stream. | |||
| 292 | 292 | ||
| 293 | 293 | :func:`izip` should only be used with unequal length inputs when you don't | |
| 294 | 294 | 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. | ||
| 296 | 296 | ||
| 297 | 297 | ||
| 298 | - .. function:: izip_longest(*iterables[, fillvalue]) | ||
| 298 | + .. function:: zip_longest(*iterables[, fillvalue]) | ||
| 299 | 299 | ||
| 300 | 300 | Make an iterator that aggregates elements from each of the iterables. If the | |
| 301 | 301 | iterables are of uneven length, missing values are filled-in with *fillvalue*. | |
| 302 | 302 | Iteration continues until the longest iterable is exhausted. Equivalent to:: | |
| 303 | 303 | ||
| 304 | - def izip_longest(*args, **kwds): | ||
| 304 | + def zip_longest(*args, **kwds): | ||
| 305 | 305 | fillvalue = kwds.get('fillvalue') | |
| 306 | 306 | def sentinel(counter = ([fillvalue]*(len(args)-1)).pop): | |
| 307 | 307 | yield counter() # yields the fillvalue, or raises IndexError | |
@@ -313,7 +313,7 @@ loops that truncate the stream. | |||
| 313 | 313 | except IndexError: | |
| 314 | 314 | pass | |
| 315 | 315 | ||
| 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` | ||
| 317 | 317 | function should be wrapped with something that limits the number of calls (for | |
| 318 | 318 | example :func:`islice` or :func:`takewhile`). | |
| 319 | 319 | ||
@@ -568,7 +568,7 @@ which incur interpreter overhead. :: | |||
| 568 | 568 | ||
| 569 | 569 | def all(seq, pred=None): | |
| 570 | 570 | "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): | ||
| 572 | 572 | return False | |
| 573 | 573 | return True | |
| 574 | 574 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ | |||
| 12 | 12 | import os | |
| 13 | 13 | import stat | |
| 14 | 14 | import warnings | |
| 15 | - from itertools import ifilterfalse, izip | ||
| 15 | + from itertools import filterfalse, izip | ||
| 16 | 16 | ||
| 17 | 17 | __all__ = ["cmp","dircmp","cmpfiles"] | |
| 18 | 18 | ||
@@ -133,8 +133,8 @@ def phase1(self): # Compute common names | |||
| 133 | 133 | a = dict(izip(map(os.path.normcase, self.left_list), self.left_list)) | |
| 134 | 134 | b = dict(izip(map(os.path.normcase, self.right_list), self.right_list)) | |
| 135 | 135 | 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))) | ||
| 138 | 138 | ||
| 139 | 139 | def phase2(self): # Distinguish files, directories, funnies | |
| 140 | 140 | self.common_dirs = [] | |
@@ -276,7 +276,7 @@ def _cmp(a, b, sh, abs=abs, cmp=cmp): | |||
| 276 | 276 | # Return a copy with items that occur in skip removed. | |
| 277 | 277 | # | |
| 278 | 278 | def _filter(flist, skip): | |
| 279 | - return list(ifilterfalse(skip.__contains__, flist)) | ||
| 279 | + return list(filterfalse(skip.__contains__, flist)) | ||
| 280 | 280 | ||
| 281 | 281 | ||
| 282 | 282 | # Demonstration and testing. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,16 +324,16 @@ def test_ifilter(self): | |||
| 324 | 324 | self.assertRaises(TypeError, ifilter, isEven, 3) | |
| 325 | 325 | self.assertRaises(TypeError, next, ifilter(range(6), range(6))) | |
| 326 | 326 | ||
| 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))) | ||
| 337 | 337 | ||
| 338 | 338 | def test_izip(self): | |
| 339 | 339 | # XXX This is rather silly now that builtin zip() calls izip()... | |
@@ -366,25 +366,25 @@ def test_iziplongest(self): | |||
| 366 | 366 | ]: | |
| 367 | 367 | target = [tuple([arg[i] if i < len(arg) else None for arg in args]) | |
| 368 | 368 | 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) | ||
| 371 | 371 | 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) | ||
| 373 | 373 | ||
| 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 | ||
| 375 | 375 | ||
| 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'))) | ||
| 379 | 379 | ||
| 380 | - self.assertEqual(list(izip_longest('abc', 'defg', **{})), | ||
| 380 | + self.assertEqual(list(zip_longest('abc', 'defg', **{})), | ||
| 381 | 381 | 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) | ||
| 384 | 384 | ||
| 385 | 385 | 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)", | ||
| 388 | 388 | ]: | |
| 389 | 389 | try: | |
| 390 | 390 | eval(stmt, globals(), locals()) | |
@@ -394,13 +394,13 @@ def test_iziplongest(self): | |||
| 394 | 394 | self.fail('Did not raise Type in: ' + stmt) | |
| 395 | 395 | ||
| 396 | 396 | # 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')], | ||
| 398 | 398 | 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')], | ||
| 400 | 400 | list(zip('abc', 'def'))) | |
| 401 | - ids = list(map(id, izip_longest('abc', 'def'))) | ||
| 401 | + ids = list(map(id, zip_longest('abc', 'def'))) | ||
| 402 | 402 | 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')))) | ||
| 404 | 404 | self.assertEqual(len(dict.fromkeys(ids)), len(ids)) | |
| 405 | 405 | ||
| 406 | 406 | def test_product(self): | |
@@ -659,7 +659,7 @@ def test_StopIteration(self): | |||
| 659 | 659 | ||
| 660 | 660 | self.assertRaises(StopIteration, next, repeat(None, 0)) | |
| 661 | 661 | ||
| 662 | - for f in (ifilter, ifilterfalse, imap, takewhile, dropwhile, starmap): | ||
| 662 | + for f in (ifilter, filterfalse, imap, takewhile, dropwhile, starmap): | ||
| 663 | 663 | self.assertRaises(StopIteration, next, f(lambda x:x, [])) | |
| 664 | 664 | self.assertRaises(StopIteration, next, f(lambda x:x, StopNow())) | |
| 665 | 665 | ||
@@ -690,9 +690,9 @@ def test_ifilter(self): | |||
| 690 | 690 | a = [] | |
| 691 | 691 | self.makecycle(ifilter(lambda x:True, [a]*2), a) | |
| 692 | 692 | ||
| 693 | - def test_ifilterfalse(self): | ||
| 693 | + def test_filterfalse(self): | ||
| 694 | 694 | a = [] | |
| 695 | - self.makecycle(ifilterfalse(lambda x:False, a), a) | ||
| 695 | + self.makecycle(filterfalse(lambda x:False, a), a) | ||
| 696 | 696 | ||
| 697 | 697 | def test_izip(self): | |
| 698 | 698 | a = [] | |
@@ -840,14 +840,14 @@ def test_ifilter(self): | |||
| 840 | 840 | self.assertRaises(TypeError, ifilter, isEven, N(s)) | |
| 841 | 841 | self.assertRaises(ZeroDivisionError, list, ifilter(isEven, E(s))) | |
| 842 | 842 | ||
| 843 | - def test_ifilterfalse(self): | ||
| 843 | + def test_filterfalse(self): | ||
| 844 | 844 | for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)): | |
| 845 | 845 | 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))), | ||
| 847 | 847 | [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))) | ||
| 851 | 851 | ||
| 852 | 852 | def test_izip(self): | |
| 853 | 853 | for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)): | |
@@ -861,11 +861,11 @@ def test_izip(self): | |||
| 861 | 861 | def test_iziplongest(self): | |
| 862 | 862 | for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)): | |
| 863 | 863 | 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))) | ||
| 869 | 869 | ||
| 870 | 870 | def test_imap(self): | |
| 871 | 871 | for s in (range(10), range(0), range(100), (7,11), range(20,50,5)): | |
@@ -1001,7 +1001,7 @@ def gen2(x): | |||
| 1001 | 1001 | class SubclassWithKwargsTest(unittest.TestCase): | |
| 1002 | 1002 | def test_keywords_in_subclass(self): | |
| 1003 | 1003 | # count is not subclassable... | |
| 1004 | - for cls in (repeat, izip, ifilter, ifilterfalse, chain, imap, | ||
| 1004 | + for cls in (repeat, izip, ifilter, filterfalse, chain, imap, | ||
| 1005 | 1005 | starmap, islice, takewhile, dropwhile, cycle): | |
| 1006 | 1006 | class Subclass(cls): | |
| 1007 | 1007 | def __init__(self, newarg=None, *args): | |
@@ -1085,7 +1085,7 @@ def __init__(self, newarg=None, *args): | |||
| 1085 | 1085 | ||
| 1086 | 1086 | >>> def all(seq, pred=None): | |
| 1087 | 1087 | ... "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): | ||
| 1089 | 1089 | ... return False | |
| 1090 | 1090 | ... return True | |
| 1091 | 1091 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments