mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
count() should return integers #10474
This commit is contained in:
parent
2e579f0a87
commit
0b458d52f9
3 changed files with 6 additions and 2 deletions
|
@ -1033,6 +1033,8 @@ class BuiltinTest(unittest.TestCase):
|
||||||
self.assertEqual(range(3).count(1), 1)
|
self.assertEqual(range(3).count(1), 1)
|
||||||
self.assertEqual(range(3).count(2), 1)
|
self.assertEqual(range(3).count(2), 1)
|
||||||
self.assertEqual(range(3).count(3), 0)
|
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(1), 1)
|
||||||
self.assertEqual(range(10**20).count(10**20), 0)
|
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
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #10474: range().count() should return integers.
|
||||||
|
|
||||||
- Issue #10255: Fix reference leak in Py_InitializeEx(). Patch by Neil
|
- Issue #10255: Fix reference leak in Py_InitializeEx(). Patch by Neil
|
||||||
Schemenauer.
|
Schemenauer.
|
||||||
|
|
||||||
|
|
|
@ -338,9 +338,9 @@ range_count(rangeobject *r, PyObject *ob)
|
||||||
{
|
{
|
||||||
if (PyLong_CheckExact(ob) || PyBool_Check(ob)) {
|
if (PyLong_CheckExact(ob) || PyBool_Check(ob)) {
|
||||||
if (range_contains_long(r, ob))
|
if (range_contains_long(r, ob))
|
||||||
Py_RETURN_TRUE;
|
return PyLong_FromLong(1);
|
||||||
else
|
else
|
||||||
Py_RETURN_FALSE;
|
return PyLong_FromLong(0);
|
||||||
} else {
|
} else {
|
||||||
Py_ssize_t count;
|
Py_ssize_t count;
|
||||||
count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT);
|
count = _PySequence_IterSearch((PyObject*)r, ob, PY_ITERSEARCH_COUNT);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue