Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xsrange is not an iterator when called with Python ints or longs #18538

Closed
sagetrac-tmonteil mannequin opened this issue May 28, 2015 · 16 comments
Closed

xsrange is not an iterator when called with Python ints or longs #18538

sagetrac-tmonteil mannequin opened this issue May 28, 2015 · 16 comments

Comments

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented May 28, 2015

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(n-k) + 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).

Component: misc

Branch/Commit: u/tmonteil/xsrange_is_not_an_iterator_when_called_with_python_ints_or_longs @ 9101119

Reviewer: Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/18538

@sagetrac-tmonteil sagetrac-tmonteil mannequin added this to the sage-6.8 milestone May 28, 2015
@sagetrac-tmonteil
Copy link
Mannequin Author

sagetrac-tmonteil mannequin commented May 28, 2015

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 28, 2015

Commit: 4a59f33

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 28, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

4a59f33#18538 : remove redundency in linking to trac ticket.

@sagetrac-tmonteil

This comment has been minimized.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 29, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

91c1b9c#18538 : add the original example as doctest.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 29, 2015

Changed commit from 4a59f33 to 91c1b9c

@sagetrac-tmonteil
Copy link
Mannequin Author

sagetrac-tmonteil mannequin commented May 29, 2015

Author: Thierry Monteil

@a-andre
Copy link

a-andre commented May 29, 2015

comment:7

Please replace next() method by next() function. See #17398.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 31, 2015

Changed commit from 91c1b9c to 9101119

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 31, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

9101119#18538 Python3 compatibility.

@videlec
Copy link
Contributor

videlec commented Aug 3, 2015

comment:10

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

@jdemeyer
Copy link

jdemeyer commented Nov 4, 2015

comment:11

I also think it's better to use iter(foo) instead of foo.__iter__().

@jdemeyer
Copy link

jdemeyer commented Nov 4, 2015

comment:12

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__

@jdemeyer
Copy link

comment:13

Fixed by #20094 instead (which removes the special cases for Python int).

@jdemeyer jdemeyer removed this from the sage-6.10 milestone Feb 22, 2016
@jdemeyer
Copy link

Changed author from Thierry Monteil to none

@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants