ipython/ipython — pull request #2134 by bfroehle (2012-07-13 21:52:39+00:00)
Title: Apply 2to3 `next` fix.

Continuing on the Python 2/3 compatibility (which I'll refer to as '2and3') from #2095 and #2100, I propose to include the changes from running `2to3 -f next`:
> Converts the use of iterator’s `next()` methods to the `next()` function. It also renames `next()` methods to `__next__()`.

One small issue is the behavior of `next(x)` on user defined classes:

Consider `test_next.py`
```
class X(object):
def __init__(self, iterable):
self.iterator = iter(iterable)
def __iter__(self):
return self
def __next__(self):
print("__next__ called")
return next(self.iterator)
def next(self):
print("next called")
return next(self.iterator)

x = X([1,2,3])
next(x)
```
Which we will run in Python 2.7 and 3.2:
```
$ python2.7 next_test.py
next called
$ python3.2 next_test.py
__next__ called
```

To work around this difference, I've just set `next = __next__` manually after applying the 2to3 fix. This also maintains compatibility with any third party code which calls `x.next()`.