# Buggy code
def write(self, *ignored):
    docwriter = ManualPageWriter(self)
    docsettings = OptionParser(
        defaults=self.env.settings, components=(docwriter,), read_config_files=True
    ).get_default_values()

    self.info(bold("writing... "), nonl=True)

    for info in self.config.man_pages:
        docname, name, description, authors, section = info
        if isinstance(authors, string_types):
            if authors:
                authors = [authors]
            else:
                authors = []

        targetname = "%s.%s" % (name, section)
        self.info(darkgreen(targetname) + " { ", nonl=True)
        destination = FileOutput(
            destination_path=path.join(self.outdir, targetname), encoding="utf-8"
        )

        tree = self.env.get_doctree(docname)
        docnames = set()
        largetree = inline_all_toctrees(self, docnames, docname, tree, darkgreen)
        self.info("} ", nonl=True)
        self.env.resolve_references(largetree, docname, self)
        # remove pending_xref nodes
        for pendingnode in largetree.traverse(addnodes.pending_xref):
            pendingnode.replace_self(pendingnode.children)

        largetree.settings = docsettings
        largetree.settings.title = name
        largetree.settings.subtitle = description
        largetree.settings.authors = authors
        largetree.settings.section = section

        docwriter.write(largetree, destination)
    self.info()


# 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 209, in build_update
self.build(['__all__'], to_build)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/builders/__init__.py", line 276, in build
self.write(docnames, list(updated_docnames), method)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/builders/latex.py", line 97, in write
self.config.latex_appendices or []))
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/builders/latex.py", line 133, in assemble_doctree
self.env.resolve_references(largetree, indexfile, self)
File "/Users/tkomiya/.buildout/buildout-eggs/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1327, in resolve_references
for node in doctree.traverse(addnodes.pending_xref):
File "/Users/tkomiya/.buildout/buildout-eggs/docutils-0.12-py2.7.egg/docutils/nodes.py", line 252, in traverse
return self._fast_traverse(condition)
File "/Users/tkomiya/.buildout/buildout-eggs/docutils-0.12-py2.7.egg/docutils/nodes.py", line 196, in _fast_traverse
result.extend(child._fast_traverse(cls))
File "/Users/tkomiya/.buildout/buildout-eggs/docutils-0.12-py2.7.egg/docutils/nodes.py", line 196, in _fast_traverse
result.extend(child._fast_traverse(cls))
...
File "/Users/tkomiya/.buildout/buildout-eggs/docutils-0.12-py2.7.egg/docutils/nodes.py", line 196, in _fast_traverse
result.extend(child._fast_traverse(cls))
File "/Users/tkomiya/.buildout/buildout-eggs/docutils-0.12-py2.7.egg/docutils/nodes.py", line 193, in _fast_traverse
if isinstance(self, cls):
RuntimeError: maximum recursion depth exceeded while calling a Python object

# Fixed code
def write(self, *ignored):
    docwriter = ManualPageWriter(self)
    docsettings = OptionParser(
        defaults=self.env.settings, components=(docwriter,), read_config_files=True
    ).get_default_values()

    self.info(bold("writing... "), nonl=True)

    for info in self.config.man_pages:
        docname, name, description, authors, section = info
        if isinstance(authors, string_types):
            if authors:
                authors = [authors]
            else:
                authors = []

        targetname = "%s.%s" % (name, section)
        self.info(darkgreen(targetname) + " { ", nonl=True)
        destination = FileOutput(
            destination_path=path.join(self.outdir, targetname), encoding="utf-8"
        )

        tree = self.env.get_doctree(docname)
        docnames = set()
        largetree = inline_all_toctrees(
            self, docnames, docname, tree, darkgreen, [docname]
        )
        self.info("} ", nonl=True)
        self.env.resolve_references(largetree, docname, self)
        # remove pending_xref nodes
        for pendingnode in largetree.traverse(addnodes.pending_xref):
            pendingnode.replace_self(pendingnode.children)

        largetree.settings = docsettings
        largetree.settings.title = name
        largetree.settings.subtitle = description
        largetree.settings.authors = authors
        largetree.settings.section = section

        docwriter.write(largetree, destination)
    self.info()