Changes between Initial Version and Version 1 of Ticket #22561


Ignore:
Timestamp:
03/10/17 10:55:30 (5 years ago)
Author:
jdemeyer
Comment:

I think it would be better to implement __iter__ instead.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #22561

    • Property Component changed from number fields to interfaces
    • Property Authors changed from to Jeroen Demeyer
  • Ticket #22561 – Description

    initial v1  
    11The following reasonable and apparently innocuous code sends Sage into an infinite loop:
    22
     3{{{
    34sage: p = pari('x^2 + x + 1')
    45sage: list(p)
     6}}}
    57
    68The reason is that the gen object has no {{{__iter__}}} method, but it has a {{{__getitem__}}} method which accepts any integer index and returns 0 for indices larger than the degree of the polynomial.  Since there is no {{{__iter__}}} method, python builds an iterator using {{{__getitem__}}}.
    7 
    8 There is a simple fix: {{{__getitem__}}} should raise an {{{IndexError}}} when the index is larger than the degree.  I also think it should raise an {{{IndexError}}} when the index is negative.