New submission from Shashank <shashank.sunny.si...@gmail.com>: -- Converting the discussion here http://mail.python.org/pipermail/python-list/2010-November/1259601.html to a bug report (+nosy for everyone that responded, quoting the initial message for context)
Are there any promises made with regard to final state of the underlying sequence that islice slices? for example consider this >>> from itertools import * >>> c = count() >>> list(islice(c, 1, 3, 50)) [1] >>> c.next() 51 Now, the doc [1] says "If stop is None, then iteration continues until the iterator is exhausted, if at all; otherwise, it stops at the specified position". It clearly is not stopping at stop (3). Further, the doc gives an example of how this is *equivalent* to a generator defined in the same section. It turns out, these two are not exactly the same if the side-effect of the code is considered on the underlying sequence. Redefining islice using the generator function defined in the doc gives different (and from one pov, expected) result >>> def islice(iterable, *args): ... # islice('ABCDEFG', 2) --> A B ... >>> c = count() >>> list(islice(c, 1, 3, 50)) [1] >>> c.next() 2 While "fixing" this should be rather easy in terms of the change in code required it might break any code depending on this seemingly incorrect behavior ---------- components: Interpreter Core messages: 120482 nosy: ned.deily, rhettinger, shashank, terry.reedy priority: normal severity: normal status: open title: Final state of underlying sequence in islice type: behavior versions: Python 2.7, Python 3.1, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10323> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com