-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Python 3 preparation: Iterator protocol uses .next() in Py2 but __next__() in Py3 #18802
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch: u/aapitzsch/18802 |
Author: André Apitzsch |
Commit: |
New commits:
|
comment:5
Are you sure that all these things are really iterators ? |
comment:6
Replying to @fchapoton:
Yes. |
comment:7
I do not quite agree with that. The next methods in permutation and partition are not really iterators (they are implemented on elements, not on a set, and they return False when they cannot return something), and should in fact not be called using next(p) but rather as a method p.next(). Of course, it may be convenient to use next(p) as a shortcut, but this is not the usual semantics of iterators, so I would rather deprecate that. |
Reviewer: Frédéric Chapoton |
comment:8
ok, let us do that, despite the fact that some are not really iterators. |
Changed branch from u/aapitzsch/18802 to |
When defining a custom iterator one has to define a method that returns the next item. In Python 3 this method is called
next()
while in Python 3 this is the special method__next__()
.More information can be found in http://python-future.org/compatible_idioms.html#custom-iterators and http://python-future.org/what_else.html#custom-iterators.
Remark: To advance some iterator
it
in Py2 often this method is called directlyit.next()
.But since Python 2.6 there is the builtin function
next()
which is compatible between Py2 and Py3: in Py2 it calls the iterator methodnext()
while in Py3 it calls the special method__next__()
.Ticket #16075 addresses the (stage 1) conversion from
it.next()
tonext(it)
.This ticket is tracked as a dependency of meta-ticket #16052.
Component: python3
Author: André Apitzsch
Branch/Commit:
840f968
Reviewer: Frédéric Chapoton
Issue created by migration from https://trac.sagemath.org/ticket/18802
The text was updated successfully, but these errors were encountered: