code: def _traverse_toctree(
      traversed: set[str],
      parent: str | None,
      docname: str,
      toctree_includes: dict[str, list[str]],
  ) -> Iterator[tuple[str | None, str]]:
      if parent == docname:
          logger.warning(
              __("self referenced toctree found. Ignored."),
              location=docname,
              type="toc",
              subtype="circular",
          )
          return
  
      # traverse toctree by pre-order
      yield parent, docname
      traversed.add(docname)
  
      for child in toctree_includes.get(docname, ()):
          for sub_parent, sub_docname in _traverse_toctree(
              traversed,
              docname,
              child,
              toctree_includes,
          ):
              if sub_docname not in traversed:
                  yield sub_parent, sub_docname
                  traversed.add(sub_docname)
  
imports: from __future__ import annotations
  import functools
  import os
  import pickle
  import time
  from collections import defaultdict
  from copy import copy
  from os import path
  from typing import TYPE_CHECKING, Any, Callable, NoReturn
  from sphinx import addnodes
  from sphinx.environment.adapters import toctree
  from sphinx.errors import BuildEnvironmentError, DocumentError, ExtensionError, SphinxError
  from sphinx.locale import __
  from sphinx.transforms import SphinxTransformer
  from sphinx.util import DownloadFiles, FilenameUniqDict, logging
  from sphinx.util.docutils import LoggingReporter
  from sphinx.util.i18n import CatalogRepository, docname_to_domain
  from sphinx.util.nodes import is_translatable
  from sphinx.util.osutil import canon_path, os_path
label_desc: Use image node_id 3 for calling a global function with example usage: _traverse_toctree(traversed, parent, docname, toctree_includes) without return types