code: def validate_set_members(
      vals: types.AnyVal | set[types.AnyVal],
      val_type: Type[Any] | tuple[Type[Any], ...],
      valid_vals: Optional[set[types.AnyVal]] = None,
  ) -> set[types.AnyVal]:
      """
      Validate values that must be of a certain type and (optionally) found among
      a set of known valid values.
  
      Args:
          vals: Value or values to validate.
          val_type: Type(s) of which all ``vals`` must be instances.
          valid_vals: Set of valid values in which all ``vals`` must be found.
  
      Return:
          set[obj]: Validated values.
  
      Raises:
          TypeError
          ValueError
      """
      vals = cast(set, to_collection(vals, val_type, set))
      if valid_vals is not None:
          if not isinstance(valid_vals, set):
              valid_vals = set(valid_vals)
          if not all(val in valid_vals for val in vals):
              raise ValueError(
                  f"values {vals.difference(valid_vals)} are invalid; "
                  f"valid values are {valid_vals}"
              )
      return vals
  
imports: from __future__ import annotations
  import inspect
  import logging
  import pathlib
  import sys
  import warnings
  from typing import Any, Callable, Collection, Iterable, Literal, Optional, Type, Union, cast
  from .None import errors
  from .None import types
label_desc: Use image node_id 12 for calling a global function with example usage: validate_set_members(vals, val_type, valid_vals) and returns: vals