homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Weird `slice.stop or sys.maxint`
Type: behavior Stage:
Components: Documentation Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: bbrazil, cool-RR, docs@python, ezio.melotti, mark.dickinson, rhettinger, serhiy.storchaka, ysj.ray
Priority: low Keywords: easy, patch

Created on 2011年04月22日 17:37 by cool-RR, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue11908-islice-docs.patch bbrazil, 2012年07月07日 09:46 review
Messages (7)
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.
msg164796 - (view) Author: Brian Brazil (bbrazil) * Date: 2012年07月07日 09:46
The attached patch fixes this
msg176756 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012年12月01日 20:49
LGTM. However note, that for 2.7 the patch should be modified (maxsize -> maxint, range -> xrange).
msg176800 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2012年12月02日 17:18
ysj: The "equivalent" means "roughly equivalent" not "precisely equivalent". The purpose of the code in the docs is to help communicate what islice() is all about. Practicality beats purity in this regard. I know of no one who has ever been mislead by the islice() docs.
I don't really like the proposed patch -- it improves a bit on technical accuracy but forgoes readability and still falls short on what stop=None does and on which arguments are required. 
That said, I don't really like the current version of the "roughly equivalent code either". It should probably be rewritten completely (no longer using slice() and it should show the actual looping logic. For clarity, it may be helpful to split it into two code-equivalents, one for the finite case (where stop is specified) and one for the infinite case (where stop is None). 
As it stands, the examples are beating the code equivalent when it comes to communicating what islice() does. I don't want to lengthen the code fragment unless it becomes *both* more communicative and more accurate.
msg192848 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013年07月11日 07:24
Closing for the reasons lists above.
History
Date User Action Args
2022年04月11日 14:57:16adminsetgithub: 56117
2013年07月11日 07:24:27rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg192848
2013年07月07日 21:29:50terry.reedysetversions: - Python 3.2
2012年12月27日 20:15:49serhiy.storchakasetstage: commit review ->
2012年12月02日 17:18:40rhettingersetmessages: + msg176800
2012年12月02日 16:41:11rhettingersetpriority: normal -> low
2012年12月02日 10:20:31mark.dickinsonsetnosy: + mark.dickinson
2012年12月01日 20:49:22serhiy.storchakasetversions: + Python 3.4
nosy: + serhiy.storchaka

messages: + msg176756

stage: needs patch -> commit review
2012年07月07日 09:46:55bbrazilsetfiles: + issue11908-islice-docs.patch

nosy: + bbrazil
messages: + msg164796

keywords: + patch
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

AltStyle によって変換されたページ (->オリジナル) /