code: def state_kept(link):
      """Keeps the previous state of a given link.
  
      This is a context manager that saves saves the current state of the link
      before entering the context, and then restores the saved state after
      escaping the context.
  
      This will just ignore non-Recurrent links.
  
         .. code-block:: python
  
            # Suppose the link is in a state A
            assert link.get_state() is A
  
            with state_kept(link):
                # The link is still in a state A
                assert link.get_state() is A
  
                # After evaluating the link, it may be in a different state
                y1 = link(x1)
                assert link.get_state() is not A
  
            # After escaping from the context, the link is in a state A again
            # because of the context manager
            assert link.get_state() is A
      """
      if isinstance(link, Recurrent):
          link.push_and_keep_state()
          yield
          link.pop_state()
      else:
          yield
  
imports: from abc import ABCMeta
  from abc import abstractmethod
  import collections
  import contextlib
  import chainer
label_desc: Use image node_id 6 for calling a global function with example usage: state_kept(link) without return types