Opened 6 years ago
Closed 5 years ago
#18538 closed defect (duplicate)
xsrange is not an iterator when called with Python ints or longs
Reported by:  tmonteil  Owned by:  

Priority:  major  Milestone:  sageduplicate/invalid/wontfix 
Component:  misc  Keywords:  
Cc:  Merged in:  
Authors:  Reviewers:  Jeroen Demeyer  
Report Upstream:  N/A  Work issues:  
Branch:  u/tmonteil/xsrange_is_not_an_iterator_when_called_with_python_ints_or_longs (Commits, GitHub, GitLab)  Commit:  91011192c160bf352906971ca0cd62e6ef18e954 
Dependencies:  Stopgaps: 
Description (last modified by )
As reported in this ask question, there is a problem with ellipsis_iter
:
sage: r = lambda n: (n(n%2))//2 sage: for n in range(6): ....: print([r(nk) + r(n+k) for k in (n..n)]) AttributeError: 'xrange' object has no attribute 'next'
This is due to the fact that, while xsrange
claims to return an iterator, it does not provide a .next()
method when called with Python ints or longs:
sage: xsrange(int(42)).next() AttributeError: 'xrange' object has no attribute 'next'
This is because in those cases, it returns an xrange
object (which is only an iterable).
Change History (15)
comment:1 Changed 6 years ago by
 Branch set to u/tmonteil/xsrange_is_not_an_iterator_when_called_with_python_ints_or_longs
comment:2 Changed 6 years ago by
 Commit set to 4a59f332523192b4fd236f3c3e0533049eff9f37
comment:3 Changed 6 years ago by
 Description modified (diff)
comment:4 Changed 6 years ago by
 Commit changed from 4a59f332523192b4fd236f3c3e0533049eff9f37 to 91c1b9c81f40b530f0e6b57971abcea5f4f6f301
Branch pushed to git repo; I updated commit sha1. New commits:
91c1b9c  #18538 : add the original example as doctest.

comment:5 Changed 6 years ago by
 Status changed from new to needs_review
comment:6 Changed 6 years ago by
comment:7 Changed 6 years ago by
 Status changed from needs_review to needs_work
Please replace next()
method by next()
function. See #17398.
comment:8 Changed 6 years ago by
 Commit changed from 91c1b9c81f40b530f0e6b57971abcea5f4f6f301 to 91011192c160bf352906971ca0cd62e6ef18e954
Branch pushed to git repo; I updated commit sha1. New commits:
9101119  #18538 Python3 compatibility.

comment:9 Changed 6 years ago by
 Status changed from needs_work to needs_review
comment:10 Changed 6 years ago by
Hello,
Why xsrange
should have a next
method?
sage: next(xrange(10)) Traceback (most recent call last): ... TypeError: xrange object is not an iterator
I think that we should keep compatibility between xsrange
and xrange
.
Vincent
comment:11 Changed 5 years ago by
 Milestone changed from sage6.8 to sage6.10
 Status changed from needs_review to needs_work
I also think it's better to use iter(foo)
instead of foo.__iter__()
.
comment:12 Changed 5 years ago by
This:
``.next()`` or a ``.__next__()`` method
should be replaced by
``.__next__()`` method
But even then, I find it a bit confusing that you talk about a __next__
method and then show two tests not explicitly involving __next__
comment:13 Changed 5 years ago by
 Milestone changed from sage6.10 to sageduplicate/invalid/wontfix
 Status changed from needs_work to needs_review
Fixed by #20094 instead (which removes the special cases for Python int
).
comment:14 Changed 5 years ago by
 Reviewers set to Jeroen Demeyer
 Status changed from needs_review to positive_review
comment:15 Changed 5 years ago by
 Resolution set to duplicate
 Status changed from positive_review to closed
Branch pushed to git repo; I updated commit sha1. New commits:
#18538 : remove redundency in linking to trac ticket.