diff options
| author | Jarrod Millman <jarrod.millman@gmail.com> | 2019-10-17 19:46:32 -0700 |
|---|---|---|
| committer | Jarrod Millman <jarrod.millman@gmail.com> | 2019-10-18 00:47:00 -0700 |
| commit | d50eef197f1e7f452dee8b85c2cec3039124f43c (patch) | |
| tree | 215dac7ba13b99bd080b9ff9236e173e085beb01 /networkx | |
| parent | 6489993fc8a57d3ae903d3cff4f28484b5b54583 (diff) | |
| download | networkx-d50eef197f1e7f452dee8b85c2cec3039124f43c.tar.gz | |
Use yield from
Diffstat (limited to 'networkx')
| -rw-r--r-- | networkx/algorithms/community/label_propagation.py | 3 | ||||
| -rw-r--r-- | networkx/algorithms/similarity.py | 17 | ||||
| -rw-r--r-- | networkx/algorithms/traversal/beamsearch.py | 4 | ||||
| -rw-r--r-- | networkx/algorithms/traversal/breadth_first_search.py | 4 | ||||
| -rw-r--r-- | networkx/utils/union_find.py | 4 |
5 files changed, 11 insertions, 21 deletions
diff --git a/networkx/algorithms/community/label_propagation.py b/networkx/algorithms/community/label_propagation.py index 18553790..ec750fac 100644 --- a/networkx/algorithms/community/label_propagation.py +++ b/networkx/algorithms/community/label_propagation.py @@ -97,8 +97,7 @@ def asyn_lpa_communities(G, weight=None, seed=None): labels[node] = seed.choice(best_labels) cont = True - # TODO In Python 3.3 or later, this should be `yield from ...`. - return iter(groups(labels).values()) + yield from groups(labels).values() @not_implemented_for('directed') diff --git a/networkx/algorithms/similarity.py b/networkx/algorithms/similarity.py index 48fe552c..f558ba64 100644 --- a/networkx/algorithms/similarity.py +++ b/networkx/algorithms/similarity.py @@ -791,9 +791,8 @@ def optimize_edit_paths(G1, G2, node_match=None, edge_match=None, continue other.append(((i, j), Cv_ij, xy, Ce_xy, Cv.C[i, j] + localCe.ls)) - # yield from - for t in sorted(other, key=lambda t: t[4] + t[1].ls + t[3].ls): - yield t + yield from sorted(other, key=lambda t: t[4] + t[1].ls + t[3].ls) + def get_edit_paths(matched_uv, pending_u, pending_v, Cv, matched_gh, pending_g, pending_h, Ce, matched_cost): @@ -873,13 +872,11 @@ def optimize_edit_paths(G1, G2, node_match=None, edge_match=None, H = list((pending_h.pop(y) if y < len(pending_h) else None) for y in reversed(sortedy)) - # yield from - for t in get_edit_paths(matched_uv, pending_u, pending_v, - Cv_ij, - matched_gh, pending_g, pending_h, - Ce_xy, - matched_cost + edit_cost): - yield t + yield from get_edit_paths(matched_uv, pending_u, pending_v, + Cv_ij, + matched_gh, pending_g, pending_h, + Ce_xy, + matched_cost + edit_cost) # backtrack if u is not None: diff --git a/networkx/algorithms/traversal/beamsearch.py b/networkx/algorithms/traversal/beamsearch.py index 181c68c7..18981bcd 100644 --- a/networkx/algorithms/traversal/beamsearch.py +++ b/networkx/algorithms/traversal/beamsearch.py @@ -93,6 +93,4 @@ def bfs_beam_edges(G, source, value, width=None): # `bfs_edges(G, source)` but with a sorted enqueue step. return iter(sorted(G.neighbors(v), key=value, reverse=True)[:width]) - # TODO In Python 3.3+, this should be `yield from ...` - for e in generic_bfs_edges(G, source, successors): - yield e + yield from generic_bfs_edges(G, source, successors) diff --git a/networkx/algorithms/traversal/breadth_first_search.py b/networkx/algorithms/traversal/breadth_first_search.py index 68e7727d..657793e9 100644 --- a/networkx/algorithms/traversal/breadth_first_search.py +++ b/networkx/algorithms/traversal/breadth_first_search.py @@ -161,9 +161,7 @@ def bfs_edges(G, source, reverse=False, depth_limit=None): successors = G.predecessors else: successors = G.neighbors - # TODO In Python 3.3+, this should be `yield from ...` - for e in generic_bfs_edges(G, source, successors, depth_limit): - yield e + yield from generic_bfs_edges(G, source, successors, depth_limit) def bfs_tree(G, source, reverse=False, depth_limit=None): diff --git a/networkx/utils/union_find.py b/networkx/utils/union_find.py index c0e755a4..bba4ec17 100644 --- a/networkx/utils/union_find.py +++ b/networkx/utils/union_find.py @@ -94,9 +94,7 @@ class UnionFind: for x in self.parents.keys(): _ = self[x] # Evaluated for side-effect only - # TODO In Python 3.3+, this should be `yield from ...`. - for block in groups(self.parents).values(): - yield block + yield from groups(self.parents).values() def union(self, *objects): """Find the sets containing the objects and merge them all.""" |
