[Patches] [ python-Patches-830070 ] itertoolsmodule.c: islice error messages (827190)

SourceForge.net noreply at sourceforge.net
Sat Oct 25 06:31:09 EDT 2003


Patches item #830070, was opened at 2003-10-25 12:31
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=830070&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Johan M. Hahn (johahn)
Assigned to: Nobody/Anonymous (nobody)
Summary: itertoolsmodule.c: islice error messages (827190)

Initial Comment:
>>> import itertools
>>> itertools.islice('abc', 0)
<itertools.islice object at 0x00A397B0>
>>> itertools.islice('abc', -2)

Traceback (most recent call last):
  File "<pyshell#37>", line 1, in -toplevel-
    itertools.islice([1,2,3], -2)
ValueError: Indices for islice() must be positive.

Error message is changed to "Indices for islice() must be 
non-negative." since 0 is allowed.

>>> itertools.islice('abc', -1)

Traceback (most recent call last):
  File "<pyshell#38>", line 1, in -toplevel-
    itertools.islice([1,2,3], -1)
ValueError: Stop argument must be an integer or None.

Clearly -1 is an integer. This was due to some 
optimization in itertoolsmodule.c. If PyInt_AsLong 
returned -1 it was taken as a conversion error. I added 
an additional else statement to distinguish the two cases 
that change the variable to -2 if it was in fact -1 to 
begin with. A little 'hacky' but it seems like the best 
soloution and it doesn't undo the optimization.

...johahn

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=830070&group_id=5470



More information about the Patches mailing list