classification
Title: heapq pure python version uses islice without guarding for negative counts
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Ronny.Pfannschmidt, alex, petri.lehtinen, python-dev, rhettinger
Priority: low Keywords:

Created on 2011-10-27 08:50 by Ronny.Pfannschmidt, last changed 2011-10-30 21:38 by rhettinger. This issue is now closed.

Messages (6)
msg146483 - (view) Author: Ronny Pfannschmidt (Ronny.Pfannschmidt) Date: 2011-10-27 08:50
the problem manifests when calling with negative counts

when the c versions are used, a empty list is returned,
however if the pure python version is called islice errors out
msg146531 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-10-28 03:09
The behavior is undefined for negative inputs, so implementations are free to the most expedient choices.
msg146621 - (view) Author: Ronny Pfannschmidt (Ronny.Pfannschmidt) Date: 2011-10-29 20:43
however some basic consistency between the cpython and pure python versions within the stdlib would be nice

since it basically implicitly breaks unaware code on non cpython
msg146659 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-10-30 21:29
New changeset 57f73b0f921c by Raymond Hettinger in branch '2.7':
Issue 13274:  Make the pure python code for heapq more closely match the C implementation for an undefined corner case.
http://hg.python.org/cpython/rev/57f73b0f921c
msg146660 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-10-30 21:33
New changeset 155e57a449b5 by Raymond Hettinger in branch '3.2':
Issue 13274:  Make the pure python code for heapq more closely match the C implementation for an undefined corner case.
http://hg.python.org/cpython/rev/155e57a449b5
msg146661 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-10-30 21:38
I went ahead an added the guards to the pure python code.

Still disagree with your assertion that non-cpython implementations were somehow broken when an undefined behavior was implemented in a different way -- nsmallest() and nlargest() have no guaranteed meaning for negative numbers.
History
Date User Action Args
2011-10-30 21:38:15rhettingersetmessages: + msg146661
2011-10-30 21:33:59python-devsetmessages: + msg146660
2011-10-30 21:29:23python-devsetnosy: + python-dev
messages: + msg146659
2011-10-30 02:47:44rhettingersetstatus: open -> closed
resolution: not a bug
2011-10-30 01:08:38alexsetnosy: + alex
2011-10-29 20:43:13Ronny.Pfannschmidtsetmessages: + msg146621
2011-10-28 03:09:06rhettingersetpriority: normal -> low

messages: + msg146531
2011-10-27 15:39:09eric.araujosetstage: test needed
versions: - Python 2.6, Python 3.1, Python 3.4
2011-10-27 12:54:42benjamin.petersonsetnosy: + rhettinger
2011-10-27 12:28:47petri.lehtinensetnosy: + petri.lehtinen
2011-10-27 08:50:24Ronny.Pfannschmidtcreate