No attribute 'next'

maranos avatarmaranos created an issue

Hey,

if I try to autodoc a module foo.bar via

.. automodule:: foo.bar
   :members:

I get an jinja2.exceptions.UndefinedError: b"'sphinx.jinja2glue.idgen object' has no attribute 'next'"

If I move bar.py one directory above (so that it is in python's path) and autodoc just bar, everything works fine.

Below is the full stacktrace. I just got the code from Mercurial and my conf.py-file was created with sphinx-quickstart.

Thanks, maranos

# Sphinx version: 1.1pre
# Python version: 3.1.2
# Docutils version: 0.7 release
# Jinja2 version: 2.5.5
Traceback (most recent call last):
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/cmdline.py", line 188, in main
    app.build(force_all, filenames)
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/application.py", line 204, in build
    self.builder.build_update()
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/builders/__init__.py", line 196, in build_update
    'out of date' % len(to_build))
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/builders/__init__.py", line 255, in build
    self.finish()
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/builders/html.py", line 439, in finish
    self.write_domain_indices()
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/builders/html.py", line 503, in write_domain_indices
    self.handle_page(indexname, indexcontext, 'domainindex.html')
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/builders/html.py", line 723, in handle_page
    output = self.templates.render(templatename, ctx)
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/jinja2glue.py", line 127, in render
    return self.environment.get_template(template).render(context)
  File "/usr/local/lib/python3.1/dist-packages/Jinja2-2.5.5-py3.1.egg/jinja2/environment.py", line 892, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.1/dist-packages/Jinja2-2.5.5-py3.1.egg/jinja2/environment.py", line 668, in handle_exception
    raise exc_value.with_traceback(tb)
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/themes/basic/domainindex.html", line 11, in <module>
    {% set title = indextitle %}
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/themes/default/layout.html", line 13, in <module>
    {% set script_files = script_files + ['_static/sidebar.js'] %}
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/themes/basic/layout.html", line 160, in <module>
    {%- block content %}
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/themes/basic/layout.html", line 164, in <module>
    {%- block document %}
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/themes/basic/layout.html", line 170, in <module>
    {% block body %} {% endblock %}
  File "/usr/local/lib/python3.1/dist-packages/Sphinx-1.1predev_20110214-py3.1.egg/sphinx/themes/basic/domainindex.html", line 43, in <module>
    id="toggle-{{ groupid.next() }}" style="display: none" alt="-" />
  File "/usr/local/lib/python3.1/dist-packages/Jinja2-2.5.5-py3.1.egg/jinja2/sandbox.py", line 257, in call
    if not __self.is_safe_callable(__obj):
  File "/usr/local/lib/python3.1/dist-packages/Jinja2-2.5.5-py3.1.egg/jinja2/sandbox.py", line 204, in is_safe_callable
    return not (getattr(obj, 'unsafe_callable', False) or \
jinja2.exceptions.UndefinedError: b"'sphinx.jinja2glue.idgen object' has no attribute 'next'"

Comments (3)

  1. maranos

    ok, I did some research:

    clearly the jinja2glue.idgen-object from the source code has a next-method. But after building, the jinja2glue.idgen-object in the build-directory has a

    __next__
    

    method instead.

    Thus when in themes/basic/domainindex.html on line 43 groupid.next() is called, Sphinx crashes.

    Greets, Maranos

  2. foogod

    I just ran into this too.. This is clearly a case of the 2to3 conversion "fixing" something that we didn't actually want "fixed" (part of the standard behavior of 2to3 is to change "next" methods to "next" due to changes in the iterator API in Py3)

    This can probably be fixed by tweaking how 2to3 is used when generating the Py3 version of Sphinx, but until somebody implements that, I have found the following workaround:

    If you add the following lines to your conf.py, it will fixup the problem part of the code during runtime:

    import sphinx.jinja2glue
    
    if not hasattr(sphinx.jinja2glue.idgen, "next"):
      sphinx.jinja2glue.idgen.next = sphinx.jinja2glue.idgen.__next__
    
  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.