mirror of https://github.com/python/cpython
count() should return integers #10474
This commit is contained in:
parent
2e579f0a87
commit
0b458d52f9
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue