class_docstr: Context manager class that modifies behavior
  and adds side effects to stochastic functions
  i.e. callables containing Pyro primitive statements.
  
  This is the base Messenger class.
  It implements the default behavior for all Pyro primitives,
  so that the joint distribution induced by a stochastic function fn
  is identical to the joint distribution induced by ``Messenger()(fn)``.
  
  Class of transformers for messages passed during inference.
  Most inference operations are implemented in subclasses of this.
docstr: :returns: self
  :rtype: pyro.poutine.Messenger
  
  Installs this messenger at the bottom of the Pyro stack.
  
  Can be overloaded to add any additional per-call setup functionality,
  but the derived class must always push itself onto the stack, usually
  by calling super().__enter__().
  
  Derived versions cannot be overridden to take arguments
  and must always return self.
docstr_tok: [":","returns",":","self",":","rtype",":","pyro.poutine.Messenger","Installs","this","messenger","at","the","bottom","of","the","Pyro","stack",".","Can","be","overloaded","to","add","any","additional","per-call","setup","functionality",",","but","the","derived","class","must","always","push","itself","onto","the","stack",",","usually","by","calling","super","(",")",".__enter__","(",")",".","Derived","versions","can","not","be","overridden","to","take","arguments","and","must","always","return","self","."]
code: def __enter__(self) -> Self:
      """
      :returns: self
      :rtype: pyro.poutine.Messenger
  
      Installs this messenger at the bottom of the Pyro stack.
  
      Can be overloaded to add any additional per-call setup functionality,
      but the derived class must always push itself onto the stack, usually
      by calling super().__enter__().
  
      Derived versions cannot be overridden to take arguments
      and must always return self.
      """
      if self not in _PYRO_STACK:
          # if this poutine is not already installed,
          # put it on the bottom of the stack.
          _PYRO_STACK.append(self)
  
          # necessary to return self because the return value of __enter__
          # is bound to VAR in with EXPR as VAR.
          return self
      else:
          # note: currently we raise an error if trying to install a poutine twice.
          # However, this isn't strictly necessary,
          # and blocks recursive poutine execution patterns like
          # like calling self.__call__ inside of self.__call__
          # or with Handler(...) as p: with p: <BLOCK>
          # It's hard to imagine use cases for this pattern,
          # but it could in principle be enabled...
          raise ValueError("cannot install a Messenger instance twice")
  
imports: from contextlib import contextmanager
  from functools import partial
  from types import TracebackType
  from typing import Any, Callable, Iterator, List, Optional, Type, TypeVar
  from typing_extensions import ParamSpec, Self
  from pyro.poutine.runtime import _PYRO_STACK, Message
label_desc: Use image node_id 2 for calling the Messenger obj's underlying member method code with example usage: obj.__enter__() and returns: self