class_docstr: Base effect handler class for the :func:`~pyro.contrib.funsor.to_funsor`
  and :func:`~pyro.contrib.funsor.to_data` primitives.
  Any effect handlers that invoke these primitives internally or wrap
  code that does should inherit from :class:`~NamedMessenger`.
  
  This design ensures that the global name-dim mapping is reset upon handler exit
  rather than potentially persisting until the entire program terminates.
code: def _pyro_to_data(msg):
      (funsor_value,) = msg["args"]
      name_to_dim = msg["kwargs"].setdefault(
          "name_to_dim", OrderedDict()
      )
      dim_type = msg["kwargs"].setdefault("dim_type", DimType.LOCAL)
  
      batch_names = tuple(funsor_value.inputs.keys())
  
      # interpret all names/dims as requests since we only run this function once
      name_to_dim_request = name_to_dim.copy()
      for name in batch_names:
          dim = name_to_dim.get(name, None)
          name_to_dim_request[name] = (
              dim
              if isinstance(dim, DimRequest)
              else DimRequest(dim, dim_type)
          )
  
      # request and update name_to_dim in-place
      # name_to_dim.update(_DIM_STACK.allocate_name_to_dim(name_to_dim_request))
      name_to_dim.update(_DIM_STACK.allocate(name_to_dim_request))
  
      msg["stop"] = True
  
imports: from collections import OrderedDict
  from contextlib import ExitStack
  from pyro.contrib.funsor.handlers.runtime import _DIM_STACK, DimRequest, DimType, StackFrame
  from pyro.poutine.reentrant_messenger import ReentrantMessenger
label_desc: Use image node_id 4 for calling the NamedMessenger obj's underlying member method code with example usage: obj._pyro_to_data(msg) without return types