count() should return integers #10474

This commit is contained in:
Benjamin Peterson 2010-11-20 22:35:41 +00:00
parent 2e579f0a87
commit 0b458d52f9
3 changed files with 6 additions and 2 deletions

View File

@ -1033,6 +1033,8 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(range(3).count(1), 1)
self.assertEqual(range(3).count(2), 1)
self.assertEqual(range(3).count(3), 0)
self.assertIs(type(range(3).count(-1)), int)
self.assertIs(type(range(3).count(1)), int)
self.assertEqual(range(10**20).count(1), 1)
self.assertEqual(range(10**20).count(10**20), 0)

View File

@ -10,6 +10,8 @@ What's New in Python 3.2 Beta 1?
Core and Builtins
-----------------
- Issue #10474: range().count() should return integers.
- Issue #10255: Fix reference leak in Py_InitializeEx(). Patch by Neil
Schemenauer.

View File

@ -338,9 +338,9 @@ range_count(rangeobject *r, PyObject *ob)
{
if (PyLong_CheckExact(ob) || PyBool_Check(ob)) {
if (range_contains_long(r, ob))
Py_RETURN_TRUE;
return PyLong_FromLong(1);
else
Py_RETURN_FALSE;
return PyLong_FromLong(0);
} else {
Py_ssize_t count;
count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT);