[Python-checkins] r69234 - in python/branches/py3k: Lib/test/test_iterlen.py Objects/abstract.c
raymond.hettinger
python-checkins at python.org
Tue Feb 3 03:12:11 CET 2009
Author: raymond.hettinger
Date: Tue Feb 3 03:12:10 2009
New Revision: 69234
Log:
Validate that __length_hint__ returns a usable result.
Modified:
python/branches/py3k/Lib/test/test_iterlen.py
python/branches/py3k/Objects/abstract.c
Modified: python/branches/py3k/Lib/test/test_iterlen.py
==============================================================================
--- python/branches/py3k/Lib/test/test_iterlen.py (original)
+++ python/branches/py3k/Lib/test/test_iterlen.py Tue Feb 3 03:12:10 2009
@@ -208,6 +208,11 @@
def __length_hint__(self):
raise RuntimeError('hello')
+class NoneLengthHint(object):
+ def __iter__(self): return iter(range(10))
+ def __length_hint__(self):
+ return None
+
class TestLengthHintExceptions(unittest.TestCase):
def test_issue1242657(self):
@@ -219,6 +224,11 @@
self.assertRaises(RuntimeError, b.extend, BadLen())
self.assertRaises(RuntimeError, b.extend, BadLengthHint())
+ def test_invalid_hint(self):
+ # Make sure an invalid result doesn't muck-up the works
+ self.assertEqual(list(NoneLengthHint()), list(range(10)))
+
+
def test_main():
unittests = [
TestRepeat,
Modified: python/branches/py3k/Objects/abstract.c
==============================================================================
--- python/branches/py3k/Objects/abstract.c (original)
+++ python/branches/py3k/Objects/abstract.c Tue Feb 3 03:12:10 2009
@@ -105,7 +105,7 @@
PyErr_Clear();
return defaultvalue;
}
- rv = PyLong_AsSsize_t(ro);
+ rv = PyLong_Check(ro) ? PyLong_AsSsize_t(ro) : defaultvalue;
Py_DECREF(ro);
return rv;
}
More information about the Python-checkins
mailing list