code: def traverse_parent(
      node: Element, cls: Any = None
  ) -> Iterable[Element]:
      while node:
          if cls is None or isinstance(node, cls):
              yield node
          node = node.parent
  
imports: from __future__ import annotations
  import contextlib
  import re
  import unicodedata
  from typing import TYPE_CHECKING, Any, Callable
  from docutils import nodes
  from sphinx import addnodes
  from sphinx.locale import __
  from sphinx.util import logging
label_desc: Use image node_id 8 for calling a global function with example usage: traverse_parent(node, cls) without return types