code: def is_one_of_factory(
      legal_values: Sequence,
  ) -> Callable[[Any], None]:
      callables = [c for c in legal_values if callable(c)]
      legal_values = [c for c in legal_values if not callable(c)]
  
      def inner(x) -> None:
          if x not in legal_values:
              if not any(c(x) for c in callables):
                  uvals = [str(lval) for lval in legal_values]
                  pp_values = "|".join(uvals)
                  msg = f"Value must be one of {pp_values}"
                  if len(callables):
                      msg += " or a callable"
                  raise ValueError(msg)
  
      return inner
  
imports: from __future__ import annotations
  from contextlib import ContextDecorator, contextmanager
  import re
  from typing import TYPE_CHECKING, Any, Callable, Generic, NamedTuple, cast
  import warnings
  from pandas._typing import F, T
  from pandas.util._exceptions import find_stack_level
label_desc: Use image node_id 21 for calling a global function with example usage: is_one_of_factory(legal_values) and returns: inner