classification
Title: range.count returns boolean
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, belopolsky, benjamin.peterson, daniel.urban
Priority: normal Keywords:

Created on 2010-11-20 22:26 by SilentGhost, last changed 2010-11-20 22:45 by belopolsky. This issue is now closed.

Messages (5)
msg121799 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-20 22:26
>>> a = range(5)
>>> a.count(5)
False
>>> a.count(2)
True

I believe this is related to the issue9213 that introduced count and index method on the range object. According to the documentation accompanying that fix it should return an integer.
msg121802 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-11-20 22:36
r86618
msg121803 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2010-11-20 22:39
Benjamin, the docs say that it's possible to have count more than 1, depending on comparison rules. If that's the case, I'm afraid your solution might need to be adjusted.
msg121806 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-11-20 22:44
2010/11/20 SilentGhost <report@bugs.python.org>:
>
> SilentGhost <michael.mischurow+bpo@gmail.com> added the comment:
>
> Benjamin, the docs say that it's possible to have count more than 1, depending on comparison rules. If that's the case, I'm afraid your solution might need to be adjusted.

Produce a case where that's true, and I'll fix it.
msg121807 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-11-20 22:45
SilentGhost,

Benjamin's fix only affect the optimized path when the argument is int or bool.  Exotic comparison rules are handled in the else clause.
History
Date User Action Args
2010-11-20 22:45:47belopolskysetnosy: + belopolsky
messages: + msg121807
2010-11-20 22:44:57benjamin.petersonsetmessages: + msg121806
2010-11-20 22:39:59SilentGhostsetmessages: + msg121803
2010-11-20 22:36:13benjamin.petersonsetstatus: open -> closed
2010-11-20 22:36:07benjamin.petersonsetresolution: fixed

messages: + msg121802
nosy: + benjamin.peterson
2010-11-20 22:35:05daniel.urbansetnosy: + daniel.urban
2010-11-20 22:26:58SilentGhostcreate