Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/utils/contextmanagers.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 from contextlib import contextmanager | |
2 import warnings | |
3 | |
4 __all__ = ["reversed"] | |
5 | |
6 | |
7 @contextmanager | |
8 def reversed(G): | |
9 """A context manager for temporarily reversing a directed graph in place. | |
10 | |
11 This is a no-op for undirected graphs. | |
12 | |
13 Parameters | |
14 ---------- | |
15 G : graph | |
16 A NetworkX graph. | |
17 | |
18 Warning | |
19 ------- | |
20 The reversed context manager is deprecated in favor | |
21 of G.reverse(copy=False). The view allows multiple threads to use the | |
22 same graph without confusion while the context manager does not. | |
23 This context manager is scheduled to be removed in version 3.0. | |
24 """ | |
25 msg = ( | |
26 "context manager reversed is deprecated and to be removed in 3.0." | |
27 "Use G.reverse(copy=False) if G.is_directed() else G instead." | |
28 ) | |
29 warnings.warn(msg, DeprecationWarning) | |
30 | |
31 directed = G.is_directed() | |
32 if directed: | |
33 G._pred, G._succ = G._succ, G._pred | |
34 G._adj = G._succ | |
35 | |
36 try: | |
37 yield | |
38 finally: | |
39 if directed: | |
40 # Reverse the reverse. | |
41 G._pred, G._succ = G._succ, G._pred | |
42 G._adj = G._succ |