[Python-checkins] r86618 - in python/branches/py3k: Lib/test/test_builtin.py Misc/NEWS Objects/rangeobject.c

benjamin.peterson python-checkins at python.org
Sat Nov 20 23:35:41 CET 2010


Author: benjamin.peterson
Date: Sat Nov 20 23:35:41 2010
New Revision: 86618

Log:
count() should return integers #10474

Modified:
   python/branches/py3k/Lib/test/test_builtin.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Objects/rangeobject.c

Modified: python/branches/py3k/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k/Lib/test/test_builtin.py	(original)
+++ python/branches/py3k/Lib/test/test_builtin.py	Sat Nov 20 23:35:41 2010
@@ -1033,6 +1033,8 @@
         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)

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Nov 20 23:35:41 2010
@@ -10,6 +10,8 @@
 Core and Builtins
 -----------------
 
+- Issue #10474: range().count() should return integers.
+
 - Issue #10255: Fix reference leak in Py_InitializeEx().  Patch by Neil
   Schemenauer.
 

Modified: python/branches/py3k/Objects/rangeobject.c
==============================================================================
--- python/branches/py3k/Objects/rangeobject.c	(original)
+++ python/branches/py3k/Objects/rangeobject.c	Sat Nov 20 23:35:41 2010
@@ -338,9 +338,9 @@
 {
     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);


More information about the Python-checkins mailing list