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: itertoolsmodule.c: islice error messages (827190)
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: johahn, rhettinger
Priority: normal Keywords: patch

Created on 2003-10-25 10:31 by johahn, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff.txt johahn, 2003-10-25 10:40 diff -c itertoolsmodule.c.old itertoolsmodule.c.new
Messages (3)
msg44829 - (view) Author: Johan M. Hahn (johahn) Date: 2003-10-25 10:31
>>> 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
msg44830 - (view) Author: Johan M. Hahn (johahn) Date: 2003-10-25 10:40
Logged In: YES 
user_id=887415

Let me add that the code has not been compiled. I just 
noticed two missing { in the first patch and uploaded a new 
version.
msg44831 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-10-28 07:34
Logged In: YES 
user_id=80475

Fixed the error messages.  See Modules/itertoolsmodule.c 1.25
History
Date User Action Args
2022-04-11 14:56:00adminsetgithub: 39457
2003-10-25 10:31:09johahncreate