Daniel Stutzbach <dan...@stutzbachenterprises.com> added the comment:

Thank you for the patch.

The patch doesn't handle the case where the object being searched for is 
!PyLong_CheckExact.  For example, the user might pass in a sub-type of int.  
The existing range_contains supports that case, so it seems like we should 
support it in range_index and range_count.

The Sequence ABC's .index method doesn't include the optional start and stop 
parameters that are present on list.index.  Since it's not part of the ABC, 
it's not mandatory that we implement those for range.index.  The patch includes 
support for start and stop.

Attached is a greatly revised patch, with two significant changes:
- Adds support for !PyLong_CheckExact (using _PySequence_IterSearch)
- Drops support for the start and stop parameters to index

Dropping support for the start and stop parameters greatly simplified the code. 
 If we want to support start and stop, then the code will need to get more 
complicated to handle the !PyLong_CheckExact case (since PySequence_IterSearch 
doesn't support start and stop).

My patch abstracts out most of the code that had originally been in 
range_contains into a new function range_contains_long so that it can be called 
by range_contains, range_count, and range_index.  The diff makes that part look 
like a large change, but it's mostly a whitespace change (the refactored code 
lost one indentation level but is otherwise unchanged).

I uploaded Daniel Urban's patch and mine to Rietveld:
http://codereview.appspot.com/2146041/

Any strong feelings on whether range.index should support the start and stop 
arguments provided by list.index, tuple.index, and str.index, but not by 
collections.Sequence.index?

----------
Added file: http://bugs.python.org/file18714/issue9213b.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9213>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to