From 0b458d52f9c58f0a47ea448e2349704fd33a7fe3 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 20 Nov 2010 22:35:41 +0000 Subject: count() should return integers #10474 --- Lib/test/test_builtin.py | 2 ++ Misc/NEWS | 2 ++ Objects/rangeobject.c | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index d2d4fa9..4d9b5c3 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index f27c4b0..04d624c 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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. diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 9650386..2188dfb 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -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); -- cgit v0.12