diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index cb9c08878..ef92297c7 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -18,6 +18,7 @@ from sphinx.errors import PycodeError from sphinx.pycode import nodes from sphinx.pycode.pgen2 import driver, token, tokenize, parse, literals from sphinx.util import get_module_source +from sphinx.util.pycompat import next from sphinx.util.docstrings import prepare_docstring, prepare_commentdoc @@ -279,7 +280,7 @@ class ModuleAnalyzer(object): result[fullname] = (dtype, startline, endline) expect_indent = False if tok in ('def', 'class'): - name = tokeniter.next()[1] + name = next(tokeniter)[1] namespace.append(name) fullname = '.'.join(namespace) stack.append((tok, fullname, spos[0], indent)) diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 8787a144e..365cd703c 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -34,6 +34,14 @@ else: b = str +try: + next +except NameError: + # this is on Python 2, where the method is called "next" + def next(iterator): + return iterator.next() + + try: any = any all = all