class_docstr: Return a handler that records the inputs and outputs of primitive calls
  and their dependencies.
  
  Consider the following Pyro program:
  
      >>> def model(x):
      ...     s = pyro.param("s", torch.tensor(0.5))
      ...     z = pyro.sample("z", dist.Normal(x, s))
      ...     return z ** 2
  
  We can record its execution using ``trace``
  and use the resulting data structure to compute the log-joint probability
  of all of the sample sites in the execution or extract all parameters.
  
      >>> trace = pyro.poutine.trace(model).get_trace(0.0)
      >>> logp = trace.log_prob_sum()
      >>> params = [trace.nodes[name]["value"].unconstrained() for name in trace.param_nodes]
  
  :param fn: a stochastic function (callable containing Pyro primitive calls)
  :param graph_type: string that specifies the kind of graph to construct
  :param param_only: if true, only records params and not samples
  :returns: stochastic function decorated with a :class:`~pyro.poutine.trace_messenger.TraceMessenger`
docstr: Adds appropriate edges based on cond_indep_stack information
  upon exiting the context.
docstr_tok: ["Adds","appropriate","edges","based","on","cond_indep_stack","information","upon","exiting","the","context","."]
code: def __exit__(self, *args, **kwargs) -> None:
      """
      Adds appropriate edges based on cond_indep_stack information
      upon exiting the context.
      """
      if self.param_only:
          for node in list(self.trace.nodes.values()):
              if node["type"] != "param":
                  assert node["name"] is not None
                  self.trace.remove_node(node["name"])
      if self.graph_type == "dense":
          identify_dense_edges(self.trace)
      return super().__exit__(*args, **kwargs)
  
imports: import sys
  from typing import TYPE_CHECKING, Any, Callable, Literal, Optional
  from typing_extensions import Self
  from pyro.poutine.messenger import Messenger
  from pyro.poutine.trace_struct import Trace
  from pyro.poutine.util import site_is_subsample
label_desc: Use image node_id 3 for calling the TraceMessenger obj's underlying member method code with example usage: obj.__exit__() and returns: super