[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-05-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: Devin, thanks for the patch. Serhiy, I added a performance note discussing the computational complexity. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-05-22 Thread Roundup Robot
Roundup Robot added the comment: New changeset cabd7261ae80 by Raymond Hettinger in branch 'default': Issue #23086: Add start and stop arguments to the Sequence.index() mixin method. https://hg.python.org/cpython/rev/cabd7261ae80 -- nosy: +python-dev

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-09 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: I inferred from Serhiy's comment that if you override __iter__ to be efficient and not use __getitem__, this overridden behavior used to pass on to index(), but wouldn't after this patch. -- ___ Python tracker

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: > The iteration usually has linear complexity The iteration abstract method depends on indexing as well: def __iter__(self): i = 0 try: while True: v = self[i] yield v i += 1

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I afraid that the patch can change computational complexity. The iteration usually has linear complexity, but indexing can has non-constant complexity. E.g. for linked list it will cause quadratic complexity of index(). May be we should have special case for

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'm afraid you're getting lost in details that don't matter. We're trying to make the index() method more useful so that searches and be restarted where they left off. -- ___ Python tracker

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-08 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: I take it back, I don't want to copy what the list type does, because it's wrong: http://bugs.python.org/issue23204 -- ___ Python tracker ___

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-08 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: I'm going to add a test case that changes the sequence length during .index(), and just do whatever list does in that case. -- ___ Python tracker ___

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-08 Thread Josh Rosenberg
Josh Rosenberg added the comment: Note: index returns without the caller having a chance to execute code that would change the sequence length directly. But other threads could change it, as could a custom __eq__ on an object stored in the sequence (or a poorly implemented __getitem__ or __len

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-08 Thread Josh Rosenberg
Josh Rosenberg added the comment: I think it avoids len because the length might change during iteration due to side-effects of other code. Since a shrinking sequence would raise an IndexError anyway when you overran the end, it may as well not assume the length is static and just keep indexin

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-08 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: Are you sure? I noticed that __iter__ went out of its way to avoid calling len(). -- ___ Python tracker ___ _

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: Try something like this: if start < 0: start += len(self) if stop is None: stop = len(self) elif stop < 0: stop += len(self) for i in range(max(start, 0), min(stop, len(self))): i

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-07 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: Why is there no "review" link next to my second patch? -- ___ Python tracker ___ ___ Python-bugs-l

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-07 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: I modified your test case somewhat. Also, your tests uncovered an issue with negative indexes -- oops, hadn't thought of those. Fixed. Let me know what you think. -- Added file: http://bugs.python.org/file37631/issue23086.2.patch ___

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-06 Thread Raymond Hettinger
Raymond Hettinger added the comment: This test looks like it may have been a typo: self.assertEqual(seq.index('a'), 0, 1) Also, it would be nice to investigate the differences with list.index() and str.index() for the corner cases. Something along these lines: # Compare Sequence.index

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2015-01-05 Thread Devin Jeanpierre
Devin Jeanpierre added the comment: A wild patch appears! Test is included, I'm unhappy with it, because it uses one test method to test all of Sequence, but that's what the test suite does for MutableSequence. -- keywords: +patch nosy: +Devin Jeanpierre Added file: http://bugs.python.

[issue23086] Add start and stop parameters to the Sequence.index() ABC mixin method

2014-12-18 Thread Raymond Hettinger
New submission from Raymond Hettinger: Currently, the Sequence ABC doesn't support start and stop arguments for the index() method which limits its usefulness in doing repeated searches (iterating over a target value) and which limits it substitutablity for various concrete sequences such as t