classification
Title: Weird `slice.stop or sys.maxint`
Type: behavior Stage: needs patch
Components: Documentation Versions: Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: cool-RR, docs@python, ezio.melotti, rhettinger, ysj.ray
Priority: normal Keywords: easy

Created on 2011-04-22 17:37 by cool-RR, last changed 2011-11-19 13:38 by ezio.melotti.

Messages (3)
msg134276 - (view) Author: Ram Rachum (cool-RR) Date: 2011-04-22 17:37
In the documentation for `itertools.islice` I see this line:

    it = iter(xrange(s.start or 0, s.stop or sys.maxint, s.step or 1))

Is it really okay to do `s.stop or sys.maxint`? I'm assuming this was targeting `None`, but what if `s.stop == 0`? And `s.step` could (pathologically) be `0` too, no?
msg134372 - (view) Author: ysj.ray (ysj.ray) Date: 2011-04-25 07:09
`step` argument for xrange() could not be 0.

But `s.stop or sys.maxint` is really a problem, in the case of `s.stop == 0`.

So the given `Equivalent to` python code in the doc is not precisely equivalent to the c implementation. The doc needs a fix.
msg134374 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-04-25 07:51
I've got from here.  Thanks.
History
Date User Action Args
2011-11-19 13:38:38ezio.melottisetkeywords: + easy
nosy: + ezio.melotti
stage: needs patch

versions: - Python 3.1
2011-04-25 18:10:51terry.reedysetversions: - Python 2.6, Python 2.5, Python 3.4
2011-04-25 07:51:04rhettingersetmessages: + msg134374
2011-04-25 07:09:08ysj.raysetnosy: + ysj.ray
messages: + msg134372
2011-04-22 18:01:51rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2011-04-22 17:37:25cool-RRcreate