code: def _current_form(this_dg: DeltaGenerator) -> FormData | None:
      """Find the FormData for the given DeltaGenerator.
  
      Forms are blocks, and can have other blocks nested inside them.
      To find the current form, we walk up the dg_stack until we find
      a DeltaGenerator that has FormData.
      """
      if not runtime.exists():
          return None
  
      if this_dg._form_data is not None:
          return this_dg._form_data
  
      if this_dg == this_dg._main_dg:
          # We were created via an `st.foo` call.
          # Walk up the dg_stack to see if we're nested inside a `with st.form` statement.
          for dg in reversed(dg_stack.get()):
              if dg._form_data is not None:
                  return dg._form_data
      else:
          # We were created via an `dg.foo` call.
          # Take a look at our parent's form data to see if we're nested inside a form.
          parent = this_dg._parent
          if parent is not None and parent._form_data is not None:
              return parent._form_data
  
      return None
  
imports: from __future__ import annotations
  import textwrap
  from typing import TYPE_CHECKING, NamedTuple, cast
  from typing_extensions import Literal
  from streamlit import runtime
  from streamlit.errors import StreamlitAPIException
  from streamlit.proto import Block_pb2
  from streamlit.runtime.metrics_util import gather_metrics
  from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
  from streamlit.runtime.scriptrunner.script_run_context import dg_stack
  from streamlit.runtime.state import WidgetArgs, WidgetCallback, WidgetKwargs
label_desc: Use image node_id 1 for calling a global function with example usage: _current_form(this_dg) and returns: None, None, this_dg, parent, dg