[docs] [issue27212] Doc for itertools, 'islice()' implementation have unwanted behavior for recipe 'consume()'

alex0307 report at bugs.python.org
Sat Jun 4 01:33:47 EDT 2016


New submission from alex0307:

In the doc for itertools, the python implementation of islice() doesn't actually perform the iteration when given an empty slice (e.g. islice(it,3,3)). 

This is not the expected behavior for 'consume()' in the recipe given below, i.e. consume(it,3) couldn't actually advance the iterator for 3 steps ahead. Instead, the iterator stays at its starting position.

As a simple fix, in the implementation of islice(), the length of the slice object should be checked first. If it's zero, the iterator should be advanced (slice.start-1) times, and return (See islice_my.py)

----------
assignee: docs at python
components: Documentation
files: islice_my.py
messages: 267236
nosy: alex0307, docs at python
priority: normal
severity: normal
status: open
title: Doc for itertools, 'islice()' implementation have unwanted behavior for recipe 'consume()'
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file43184/islice_my.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27212>
_______________________________________


More information about the docs mailing list