docs: def apply_patch(document, patch):
    """Apply a Patch object to a document."""
    # pylint: disable=too-many-return-statements
    op = patch.op
    parent, idx = resolve_path(document, patch.path)
    if op == "add":
      return add(parent, idx, patch.value)
    elif op == "remove":
      return remove(parent, idx)
    elif op == "replace":
      return replace(parent, idx, patch.value, patch.src)
    elif op == "merge":
      return merge(parent, idx, patch.value)
    elif op == "copy":
      sparent, sidx = resolve_path(document, patch.src)
      return copy(sparent, sidx, parent, idx)
    elif op == "move":
      sparent, sidx = resolve_path(document, patch.src)
      return move(sparent, sidx, parent, idx)
    elif op == "test":
      return test(parent, idx, patch.value)
    elif op == "setremove":
      return set_remove(parent, idx, patch.value)
    elif op == "setadd":
      return set_add(parent, idx, patch.value)
    else:
      raise JSONPatchError("Invalid operator")