# Buggy code
def _walk_toctree(toctreenode, depth):
    if depth == 0:
        return
    for title, ref in toctreenode["entries"]:
        if url_re.match(ref) or ref == "self":
            # don't mess with those
            continue
        if ref in self.tocs:
            secnums = self.toc_secnumbers[ref] = {}
            _walk_toc(self.tocs[ref], secnums, depth, self.titles.get(ref))
            if secnums != old_secnumbers.get(ref):
                rewrite_needed.append(ref)


# Traceback (RuntimeError)
# Sphinx version: 1.2.2
# Python version: 2.7.7
# Docutils version: 0.12 release
# Jinja2 version: 2.7.3
# Loaded extensions:
#   sphinx.ext.oldcmarkup from /Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/ext/oldcmarkup.pyc
Traceback (most recent call last):
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/cmdline.py", line 254, in main
app.build(force_all, filenames)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/application.py", line 212, in build
self.builder.build_update()
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/builders/__init__.py", line 214, in build_update
'out of date' &amp;#37; len(to_build))
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/builders/__init__.py", line 244, in build
for docname in self.env.check_dependents(updated_docnames):
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 490, in check_dependents
to_rewrite = self.assign_section_numbers()
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1501, in assign_section_numbers
_walk_toctree(toctreenode, depth)
...
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1490, in _walk_toctree
self.titles.get(ref))
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1458, in _walk_toc
_walk_toc(subnode, secnums, depth, titlenode)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1454, in _walk_toc
_walk_toc(subnode, secnums, depth-1, titlenode)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1478, in _walk_toc
_walk_toctree(subnode, depth)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1490, in _walk_toctree
self.titles.get(ref))
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1458, in _walk_toc
_walk_toc(subnode, secnums, depth, titlenode)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1454, in _walk_toc
_walk_toc(subnode, secnums, depth-1, titlenode)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1478, in _walk_toc
_walk_toctree(subnode, depth)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1483, in _walk_toctree
for (title, ref) in toctreenode['entries']:
File "/Users/tkomiya/.buildout/buildout-eggs/docutils-0.12-py2.7.egg/docutils/nodes.py", line 566, in __getitem__
if isinstance(key, basestring):
RuntimeError: maximum recursion depth exceeded in __instancecheck__

# Fixed code
def _walk_toctree(toctreenode, depth):
    if depth == 0:
        return
    for title, ref in toctreenode["entries"]:
        if url_re.match(ref) or ref == "self" or ref in assigned:
            # don't mess with those
            continue
        if ref in self.tocs:
            secnums = self.toc_secnumbers[ref] = {}
            assigned.add(ref)
            _walk_toc(self.tocs[ref], secnums, depth, self.titles.get(ref))
            if secnums != old_secnumbers.get(ref):
                rewrite_needed.append(ref)