code: def _warning_handler_template(
      w: WarningMessage,
      debug: Optional[Callable[[WarningMessage], bool]] = None,
      rethrow: Optional[Callable[[WarningMessage], bool]] = None,
  ) -> bool:
      r"""Helper for making basic warning handlers. Typically used with functools.partial.
  
      Args:
          w: The WarningMessage to be resolved and filtered out or returned unresolved.
          debug: Optional callable used to specify that a warning should be
              resolved as a logging statement at the DEBUG level.
          rethrow: Optional callable used to specify that a warning should be
              resolved by rethrowing the warning.
  
      Returns:
          Boolean indicating whether or not the warning message was resolved.
      """
      if debug and debug(w):
          logging_debug(str(w.message))
          return True
  
      if rethrow and rethrow(w):
          warn_explicit(
              str(w.message), w.category, w.filename, w.lineno
          )
          return True
  
      return False
  
file_path: botorch/botorch/optim/utils/common.py
imports: from __future__ import annotations
  from inspect import signature
  from logging import debug
  from typing import Any, Callable, Optional, Tuple
  from warnings import warn, warn_explicit, WarningMessage
  import numpy
  from linear_operator.utils.errors import NanError, NotPSDError
label_desc: Use image node_id 3 for calling a global function with example usage: _warning_handler_template(w, debug, rethrow) and returns: False, True, True