From 30e4a1493679632ed0008131936e3206fe68a725 2012-07-13 22:59:26 From: Bradley M. Froehle Date: 2012-07-13 22:59:26 Subject: [PATCH] Apply 2to3 `next` fix. Manually set `next = __next__` for Python 2 support. --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 8cb2345..83f9f5b 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -718,10 +718,10 @@ class IPCompleter(Completer): isId = re.compile(r'\w+$').match while True: try: - ids.append(iterTokens.next()) + ids.append(next(iterTokens)) if not isId(ids[-1]): ids.pop(); break - if not iterTokens.next() == '.': + if not next(iterTokens) == '.': break except StopIteration: break diff --git a/IPython/external/pexpect/_pexpect.py b/IPython/external/pexpect/_pexpect.py index 3b8a4ea..6e9d9a7 100644 --- a/IPython/external/pexpect/_pexpect.py +++ b/IPython/external/pexpect/_pexpect.py @@ -930,7 +930,7 @@ class spawnb(object): return self - def next (self): # File-like object. + def __next__ (self): # File-like object. """This is to support iterators over a file-like object. """ @@ -940,6 +940,9 @@ class spawnb(object): raise StopIteration return result + if not PY3: + next = __next__ # File-like object. + def readlines (self, sizehint = -1): # File-like object. """This reads until EOF using readline() and returns a list containing diff --git a/IPython/frontend/qt/console/pygments_highlighter.py b/IPython/frontend/qt/console/pygments_highlighter.py index ef964d0..7d54c74 100644 --- a/IPython/frontend/qt/console/pygments_highlighter.py +++ b/IPython/frontend/qt/console/pygments_highlighter.py @@ -174,7 +174,7 @@ class PygmentsHighlighter(QtGui.QSyntaxHighlighter): def _get_format_from_document(self, token, document): """ Returns a QTextCharFormat for token by """ - code, html = self._formatter._format_lines([(token, u'dummy')]).next() + code, html = next(self._formatter._format_lines([(token, u'dummy')])) self._document.setHtml(html) return QtGui.QTextCursor(self._document).charFormat() diff --git a/IPython/testing/_paramtestpy2.py b/IPython/testing/_paramtestpy2.py index f4bfa26..102bc85 100644 --- a/IPython/testing/_paramtestpy2.py +++ b/IPython/testing/_paramtestpy2.py @@ -51,7 +51,7 @@ class ParametricTestCase(unittest.TestCase): # Test execution ok = False try: - testgen.next() + next(testgen) ok = True except StopIteration: # We stop the loop diff --git a/IPython/utils/_process_common.py b/IPython/utils/_process_common.py index 1f75c9a..00436ee 100644 --- a/IPython/utils/_process_common.py +++ b/IPython/utils/_process_common.py @@ -179,7 +179,7 @@ def arg_split(s, posix=False, strict=True): tokens = [] while True: try: - tokens.append(lex.next()) + tokens.append(next(lex)) except StopIteration: break except ValueError: diff --git a/IPython/zmq/iostream.py b/IPython/zmq/iostream.py index 7fa896c..f20a660 100644 --- a/IPython/zmq/iostream.py +++ b/IPython/zmq/iostream.py @@ -5,6 +5,7 @@ from io import StringIO from session import extract_header, Message from IPython.utils import io, text, encoding +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Globals @@ -54,9 +55,12 @@ class OutStream(object): def isatty(self): return False - def next(self): + def __next__(self): raise IOError('Read not supported on a write only stream.') + if not py3compat.PY3: + next = __next__ + def read(self, size=-1): raise IOError('Read not supported on a write only stream.') diff --git a/setup.py b/setup.py index 0e80ab5..9074f38 100755 --- a/setup.py +++ b/setup.py @@ -272,6 +272,7 @@ if 'setuptools' in sys.modules: 'lib2to3.fixes.fix_except', 'lib2to3.fixes.fix_apply', 'lib2to3.fixes.fix_repr', + 'lib2to3.fixes.fix_next', ] from setuptools.command.build_py import build_py setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}