@contextmanager
def reversed(G):
 directed = G.is_directed()
 if directed:
  G.reverse(copy=False)
 try:
  (yield)
 finally:
  if directed:
   G.reverse(copy=False)

@ contextmanager def reversed ( G ) : directed = G . is_directed ( ) if directed : G . reverse ( copy = False ) try : ( yield ) finally : if directed : G . reverse ( copy = False )
a context manager for temporarily reversing a directed graph in place .