self.assertRaises(TypeError, ifilter, isEven, 3)
self.assertRaises(TypeError, next, ifilter(range(6), range(6)))
- def test_ifilterfalse(self):
- self.assertEqual(list(ifilterfalse(isEven, range(6))), [1,3,5])
- self.assertEqual(list(ifilterfalse(None, [0,1,0,2,0])), [0,0,0])
- self.assertEqual(list(ifilterfalse(bool, [0,1,0,2,0])), [0,0,0])
- self.assertEqual(take(4, ifilterfalse(isEven, count())), [1,3,5,7])
- self.assertRaises(TypeError, ifilterfalse)
- self.assertRaises(TypeError, ifilterfalse, lambda x:x)
- self.assertRaises(TypeError, ifilterfalse, lambda x:x, range(6), 7)
- self.assertRaises(TypeError, ifilterfalse, isEven, 3)
- self.assertRaises(TypeError, next, ifilterfalse(range(6), range(6)))
+ def test_filterfalse(self):
+ self.assertEqual(list(filterfalse(isEven, range(6))), [1,3,5])
+ self.assertEqual(list(filterfalse(None, [0,1,0,2,0])), [0,0,0])
+ self.assertEqual(list(filterfalse(bool, [0,1,0,2,0])), [0,0,0])
+ self.assertEqual(take(4, filterfalse(isEven, count())), [1,3,5,7])
+ self.assertRaises(TypeError, filterfalse)
+ self.assertRaises(TypeError, filterfalse, lambda x:x)
+ self.assertRaises(TypeError, filterfalse, lambda x:x, range(6), 7)
+ self.assertRaises(TypeError, filterfalse, isEven, 3)
+ self.assertRaises(TypeError, next, filterfalse(range(6), range(6)))
def test_izip(self):
# XXX This is rather silly now that builtin zip() calls izip()...
]:
target = [tuple([arg[i] if i < len(arg) else None for arg in args])
for i in range(max(map(len, args)))]
- self.assertEqual(list(izip_longest(*args)), target)
- self.assertEqual(list(izip_longest(*args, **{})), target)
+ self.assertEqual(list(zip_longest(*args)), target)
+ self.assertEqual(list(zip_longest(*args, **{})), target)
target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X'
- self.assertEqual(list(izip_longest(*args, **dict(fillvalue='X'))), target)
+ self.assertEqual(list(zip_longest(*args, **dict(fillvalue='X'))), target)
- self.assertEqual(take(3,izip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
+ self.assertEqual(take(3,zip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
- self.assertEqual(list(izip_longest()), list(zip()))
- self.assertEqual(list(izip_longest([])), list(zip([])))
- self.assertEqual(list(izip_longest('abcdef')), list(zip('abcdef')))
+ self.assertEqual(list(zip_longest()), list(zip()))
+ self.assertEqual(list(zip_longest([])), list(zip([])))
+ self.assertEqual(list(zip_longest('abcdef')), list(zip('abcdef')))
- self.assertEqual(list(izip_longest('abc', 'defg', **{})),
+ self.assertEqual(list(zip_longest('abc', 'defg', **{})),
list(izip(list('abc')+[None], 'defg'))) # empty keyword dict
- self.assertRaises(TypeError, izip_longest, 3)
- self.assertRaises(TypeError, izip_longest, range(3), 3)
+ self.assertRaises(TypeError, zip_longest, 3)
+ self.assertRaises(TypeError, zip_longest, range(3), 3)
for stmt in [
- "izip_longest('abc', fv=1)",
- "izip_longest('abc', fillvalue=1, bogus_keyword=None)",
+ "zip_longest('abc', fv=1)",
+ "zip_longest('abc', fillvalue=1, bogus_keyword=None)",
]:
try:
eval(stmt, globals(), locals())
self.fail('Did not raise Type in: ' + stmt)
# Check tuple re-use (implementation detail)
- self.assertEqual([tuple(list(pair)) for pair in izip_longest('abc', 'def')],
+ self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')],
list(zip('abc', 'def')))
- self.assertEqual([pair for pair in izip_longest('abc', 'def')],
+ self.assertEqual([pair for pair in zip_longest('abc', 'def')],
list(zip('abc', 'def')))
- ids = list(map(id, izip_longest('abc', 'def')))
+ ids = list(map(id, zip_longest('abc', 'def')))
self.assertEqual(min(ids), max(ids))
- ids = list(map(id, list(izip_longest('abc', 'def'))))
+ ids = list(map(id, list(zip_longest('abc', 'def'))))
self.assertEqual(len(dict.fromkeys(ids)), len(ids))
def test_product(self):
self.assertRaises(StopIteration, next, repeat(None, 0))
- for f in (ifilter, ifilterfalse, imap, takewhile, dropwhile, starmap):
+ for f in (ifilter, filterfalse, imap, takewhile, dropwhile, starmap):
self.assertRaises(StopIteration, next, f(lambda x:x, []))
self.assertRaises(StopIteration, next, f(lambda x:x, StopNow()))
a = []
self.makecycle(ifilter(lambda x:True, [a]*2), a)
- def test_ifilterfalse(self):
+ def test_filterfalse(self):
a = []
- self.makecycle(ifilterfalse(lambda x:False, a), a)
+ self.makecycle(filterfalse(lambda x:False, a), a)
def test_izip(self):
a = []
self.assertRaises(TypeError, ifilter, isEven, N(s))
self.assertRaises(ZeroDivisionError, list, ifilter(isEven, E(s)))
- def test_ifilterfalse(self):
+ def test_filterfalse(self):
for s in (range(10), range(0), range(1000), (7,11), range(2000,2200,5)):
for g in (G, I, Ig, S, L, R):
- self.assertEqual(list(ifilterfalse(isEven, g(s))),
+ self.assertEqual(list(filterfalse(isEven, g(s))),
[x for x in g(s) if isOdd(x)])
- self.assertRaises(TypeError, ifilterfalse, isEven, X(s))
- self.assertRaises(TypeError, ifilterfalse, isEven, N(s))
- self.assertRaises(ZeroDivisionError, list, ifilterfalse(isEven, E(s)))
+ self.assertRaises(TypeError, filterfalse, isEven, X(s))
+ self.assertRaises(TypeError, filterfalse, isEven, N(s))
+ self.assertRaises(ZeroDivisionError, list, filterfalse(isEven, E(s)))
def test_izip(self):
for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
def test_iziplongest(self):
for s in ("123", "", range(1000), ('do', 1.2), range(2000,2200,5)):
for g in (G, I, Ig, S, L, R):
- self.assertEqual(list(izip_longest(g(s))), list(zip(g(s))))
- self.assertEqual(list(izip_longest(g(s), g(s))), list(zip(g(s), g(s))))
- self.assertRaises(TypeError, izip_longest, X(s))
- self.assertRaises(TypeError, izip_longest, N(s))
- self.assertRaises(ZeroDivisionError, list, izip_longest(E(s)))
+ self.assertEqual(list(zip_longest(g(s))), list(zip(g(s))))
+ self.assertEqual(list(zip_longest(g(s), g(s))), list(zip(g(s), g(s))))
+ self.assertRaises(TypeError, zip_longest, X(s))
+ self.assertRaises(TypeError, zip_longest, N(s))
+ self.assertRaises(ZeroDivisionError, list, zip_longest(E(s)))
def test_imap(self):
for s in (range(10), range(0), range(100), (7,11), range(20,50,5)):
class SubclassWithKwargsTest(unittest.TestCase):
def test_keywords_in_subclass(self):
# count is not subclassable...
- for cls in (repeat, izip, ifilter, ifilterfalse, chain, imap,
+ for cls in (repeat, izip, ifilter, filterfalse, chain, imap,
starmap, islice, takewhile, dropwhile, cycle):
class Subclass(cls):
def __init__(self, newarg=None, *args):
>>> def all(seq, pred=None):
... "Returns True if pred(x) is true for every element in the iterable"
-... for elem in ifilterfalse(pred, seq):
+... for elem in filterfalse(pred, seq):
... return False
... return True
};
-/* ifilterfalse object ************************************************************/
+/* filterfalse object ************************************************************/
typedef struct {
PyObject_HEAD
PyObject *func;
PyObject *it;
-} ifilterfalseobject;
+} filterfalseobject;
-static PyTypeObject ifilterfalse_type;
+static PyTypeObject filterfalse_type;
static PyObject *
-ifilterfalse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+filterfalse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *func, *seq;
PyObject *it;
- ifilterfalseobject *lz;
+ filterfalseobject *lz;
- if (type == &ifilterfalse_type &&
- !_PyArg_NoKeywords("ifilterfalse()", kwds))
+ if (type == &filterfalse_type &&
+ !_PyArg_NoKeywords("filterfalse()", kwds))
return NULL;
- if (!PyArg_UnpackTuple(args, "ifilterfalse", 2, 2, &func, &seq))
+ if (!PyArg_UnpackTuple(args, "filterfalse", 2, 2, &func, &seq))
return NULL;
/* Get iterator. */
if (it == NULL)
return NULL;
- /* create ifilterfalseobject structure */
- lz = (ifilterfalseobject *)type->tp_alloc(type, 0);
+ /* create filterfalseobject structure */
+ lz = (filterfalseobject *)type->tp_alloc(type, 0);
if (lz == NULL) {
Py_DECREF(it);
return NULL;
}
static void
-ifilterfalse_dealloc(ifilterfalseobject *lz)
+filterfalse_dealloc(filterfalseobject *lz)
{
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->func);
}
static int
-ifilterfalse_traverse(ifilterfalseobject *lz, visitproc visit, void *arg)
+filterfalse_traverse(filterfalseobject *lz, visitproc visit, void *arg)
{
Py_VISIT(lz->it);
Py_VISIT(lz->func);
}
static PyObject *
-ifilterfalse_next(ifilterfalseobject *lz)
+filterfalse_next(filterfalseobject *lz)
{
PyObject *item;
PyObject *it = lz->it;
}
}
-PyDoc_STRVAR(ifilterfalse_doc,
-"ifilterfalse(function or None, sequence) --> ifilterfalse object\n\
+PyDoc_STRVAR(filterfalse_doc,
+"filterfalse(function or None, sequence) --> filterfalse object\n\
\n\
Return those items of sequence for which function(item) is false.\n\
If function is None, return the items that are false.");
-static PyTypeObject ifilterfalse_type = {
+static PyTypeObject filterfalse_type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "itertools.ifilterfalse", /* tp_name */
- sizeof(ifilterfalseobject), /* tp_basicsize */
+ "itertools.filterfalse", /* tp_name */
+ sizeof(filterfalseobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- (destructor)ifilterfalse_dealloc, /* tp_dealloc */
+ (destructor)filterfalse_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
- ifilterfalse_doc, /* tp_doc */
- (traverseproc)ifilterfalse_traverse, /* tp_traverse */
+ filterfalse_doc, /* tp_doc */
+ (traverseproc)filterfalse_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
- (iternextfunc)ifilterfalse_next, /* tp_iternext */
+ (iternextfunc)filterfalse_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- ifilterfalse_new, /* tp_new */
+ filterfalse_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
static PyTypeObject iziplongest_type;
static PyObject *
-izip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
iziplongestobject *lz;
Py_ssize_t i;
fillvalue = PyDict_GetItemString(kwds, "fillvalue");
if (fillvalue == NULL || PyDict_Size(kwds) > 1) {
PyErr_SetString(PyExc_TypeError,
- "izip_longest() got an unexpected keyword argument");
+ "zip_longest() got an unexpected keyword argument");
return NULL;
}
}
if (it == NULL) {
if (PyErr_ExceptionMatches(PyExc_TypeError))
PyErr_Format(PyExc_TypeError,
- "izip_longest argument #%zd must support iteration",
+ "zip_longest argument #%zd must support iteration",
i+1);
Py_DECREF(ittuple);
return NULL;
}
static void
-izip_longest_dealloc(iziplongestobject *lz)
+zip_longest_dealloc(iziplongestobject *lz)
{
PyObject_GC_UnTrack(lz);
Py_XDECREF(lz->ittuple);
}
static int
-izip_longest_traverse(iziplongestobject *lz, visitproc visit, void *arg)
+zip_longest_traverse(iziplongestobject *lz, visitproc visit, void *arg)
{
Py_VISIT(lz->ittuple);
Py_VISIT(lz->result);
}
static PyObject *
-izip_longest_next(iziplongestobject *lz)
+zip_longest_next(iziplongestobject *lz)
{
Py_ssize_t i;
Py_ssize_t tuplesize = lz->tuplesize;
return result;
}
-PyDoc_STRVAR(izip_longest_doc,
-"izip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> izip_longest object\n\
+PyDoc_STRVAR(zip_longest_doc,
+"zip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> zip_longest object\n\
\n\
-Return an izip_longest object whose .__next__() method returns a tuple where\n\
+Return an zip_longest object whose .__next__() method returns a tuple where\n\
the i-th element comes from the i-th iterable argument. The .__next__()\n\
method continues until the longest iterable in the argument sequence\n\
is exhausted and then it raises StopIteration. When the shorter iterables\n\
static PyTypeObject iziplongest_type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "itertools.izip_longest", /* tp_name */
+ "itertools.zip_longest", /* tp_name */
sizeof(iziplongestobject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- (destructor)izip_longest_dealloc, /* tp_dealloc */
+ (destructor)zip_longest_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
- izip_longest_doc, /* tp_doc */
- (traverseproc)izip_longest_traverse, /* tp_traverse */
+ zip_longest_doc, /* tp_doc */
+ (traverseproc)zip_longest_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
PyObject_SelfIter, /* tp_iter */
- (iternextfunc)izip_longest_next, /* tp_iternext */
+ (iternextfunc)zip_longest_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- izip_longest_new, /* tp_new */
+ zip_longest_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
\n\
Iterators terminating on the shortest input sequence:\n\
izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
-izip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
-ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\
+zip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n\
+filterfalse(pred, seq) --> elements of seq where pred(elem) is False\n\
islice(seq, [start,] stop [, step]) --> elements from\n\
seq[start:stop:step]\n\
starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...\n\
&islice_type,
&starmap_type,
&chain_type,
- &ifilterfalse_type,
+ &filterfalse_type,
&count_type,
&izip_type,
&iziplongest_type,