code: def warnings_to(
      logger: Optional[PicklableClientLogger] = None,
  ) -> Iterator[None]:
      """A context manager to catch warnings and send them to the logger
  
      If no logger is passed, warnings propogate as they normally would.
  
      Parameters
      ----------
      logger: Optional[PicklableClientLogger] = None
          The logger to send the warnings to
      """
      # Send to a logger if one exists
      if logger:
          with warnings.catch_warnings():
  
              def to_log(
                  logger: PicklableClientLogger,
                  message: str,
                  category: Type[
                      Warning
                  ],  # Weird but that's what it is
                  filename: str,
                  lineno: int,
                  file: Optional[TextIO] = None,
                  line: Optional[str] = None,
              ) -> None:
                  logger.warning(
                      f"{filename}:{lineno} {category.__name__}:{message}"
                  )
  
              # Mypy was complaining that logger didn't exist in `to_log` see here:
              # https://mypy.readthedocs.io/en/stable/common_issues.html#narrowing-and-inner-functions
              # we explicitly pass it in and have to force it's type with `cast`
              warnings.showwarning = lambda *args: to_log(
                  cast(PicklableClientLogger, logger), *args
              )
  
              yield
      # Else do nothing, warnings go to wherever they would without this context
      else:
          yield
  
imports: from typing import Any, Dict, Iterator, Optional, TextIO, Type, cast
  import logging
  import logging.config
  import logging.handlers
  import multiprocessing
  import os
  import pickle
  import random
  import select
  import socketserver
  import struct
  import threading
  import warnings
  from contextlib import contextmanager
  import yaml
label_desc: Use image node_id 7 for calling a global function with example usage: warnings_to(logger) without return types