This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients max-alleged, petri.lehtinen, terry.reedy
Date 2011-05-25.17:41:15
SpamBayes Score 3.7856385e-10
Marked as misclassified No
Message-id <1306345276.32.0.812617899215.issue12170@psf.upfronthosting.co.za>
In-reply-to
Content
> It is certainly unusual for n to be in the sequence, but not to be able to find it.

Agreed. Doc Lib: 4.6. Sequence Types — str, bytes, bytearray, list, tuple, range says '''
s.index(i) index of the first occurence of i in s   
s.count(i) total number of occurences of i in s '''
so everything *in* a bytes should be valid for .index and .count.

>>> test = b'0120'
>>> z = b'0'
>>> zo = ord(z)
>>> z in test
True
>>> zo in test
True
>>> test.index(z)
0
>>> test.index(zo)
...
TypeError: expected an object with the buffer interface
>>> test.count(z)
2
>>> test.count(zo)
...
TypeError: expected an object with the buffer interface
# longer subsequences like b'01' also work

So I think the code for 3.2+ bytes.count() and bytes.index() should do the same branching as the code for bytes.__contains__.

The other functions you list, including .rindex are not general sequence functions but are string functions defined as taking subsequences as inputs. So they would never be used in generic code like .count and .index can be.
History
Date User Action Args
2011-05-25 17:41:16terry.reedysetrecipients: + terry.reedy, max-alleged, petri.lehtinen
2011-05-25 17:41:16terry.reedysetmessageid: <1306345276.32.0.812617899215.issue12170@psf.upfronthosting.co.za>
2011-05-25 17:41:15terry.reedylinkissue12170 messages
2011-05-25 17:41:15terry.reedycreate