code: def maybe_produces_warning(
      warning: type[Warning], condition: bool, **kwargs
  ) -> AbstractContextManager:
      """
      Return a context manager that possibly checks a warning based on the condition
      """
      if condition:
          return assert_produces_warning(warning, **kwargs)
      else:
          return nullcontext()
  
file_path: pandas/pandas/_testing/_warnings.py
imports: from __future__ import annotations
  from contextlib import AbstractContextManager, contextmanager, nullcontext
  import inspect
  import re
  import sys
  from typing import TYPE_CHECKING, Literal, cast
  import warnings
  from pandas.compat import PY311
label_desc: Use image node_id 2 for calling a global function with example usage: maybe_produces_warning(warning, condition) and returns: assert_produces_warning, nullcontext