[Python-checkins] r61073 - in python/trunk: Lib/test/test_itertools.py Modules/itertoolsmodule.c
raymond.hettinger
python-checkins at python.org
Mon Feb 25 23:42:32 CET 2008
Author: raymond.hettinger
Date: Mon Feb 25 23:42:32 2008
New Revision: 61073
Modified:
python/trunk/Lib/test/test_itertools.py
python/trunk/Modules/itertoolsmodule.c
Log:
Make sure the itertools filter functions give the same performance for func=bool as func=None.
Modified: python/trunk/Lib/test/test_itertools.py
==============================================================================
--- python/trunk/Lib/test/test_itertools.py (original)
+++ python/trunk/Lib/test/test_itertools.py Mon Feb 25 23:42:32 2008
@@ -171,6 +171,7 @@
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 @@
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)
Modified: python/trunk/Modules/itertoolsmodule.c
==============================================================================
--- python/trunk/Modules/itertoolsmodule.c (original)
+++ python/trunk/Modules/itertoolsmodule.c Mon Feb 25 23:42:32 2008
@@ -2055,7 +2055,7 @@
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 @@
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;
More information about the Python-checkins
mailing list