def process_selected(keypath, leaf):
    """Process PyTree leaves or subtrees where _is_hole_or_quote is True."""
    if isinstance(leaf, _InProgressSelectionBoundary):
      # Select this object and stop processing the tree.
      selected_by_path[keypath] = leaf.selected
      return SelectionHole(keypath)
    elif _is_hole_or_quote(leaf):
      # This is already a hole or a quote, but we shouldn't treat it like a
      # hole or quote for the purposes of this selection. Escape them by adding
      # a level of quoting.
      return SelectionQuote(leaf)
    else:
      # This is just an ordinary leaf; keep it in the remainder.
      return leaf
Process PyTree leaves or subtrees where _is_hole_or_quote is True.
penzai/core/selectors.py