Kaydet (Commit) 9d63837e authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Make sure the itertools filter functions give the same performance for func=bool as func=None.

üst df419891
......@@ -171,6 +171,7 @@ class TestBasicOps(unittest.TestCase):
def test_ifilter(self):
self.assertEqual(list(ifilter(isEven, range(6))), [0,2,4])
self.assertEqual(list(ifilter(None, [0,1,0,2,0])), [1,2])
self.assertEqual(list(ifilter(bool, [0,1,0,2,0])), [1,2])
self.assertEqual(take(4, ifilter(isEven, count())), [0,2,4,6])
self.assertRaises(TypeError, ifilter)
self.assertRaises(TypeError, ifilter, lambda x:x)
......@@ -181,6 +182,7 @@ class TestBasicOps(unittest.TestCase):
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)
......
......@@ -2055,7 +2055,7 @@ ifilter_next(ifilterobject *lz)
if (item == NULL)
return NULL;
if (lz->func == Py_None) {
if (lz->func == Py_None || lz->func == PyBool_Type) {
ok = PyObject_IsTrue(item);
} else {
PyObject *good;
......@@ -2199,7 +2199,7 @@ ifilterfalse_next(ifilterfalseobject *lz)
if (item == NULL)
return NULL;
if (lz->func == Py_None) {
if (lz->func == Py_None || lz->func == PyBool_Type) {
ok = PyObject_IsTrue(item);
} else {
PyObject *good;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment