8000 Simplify, expand and explain complicated loops in dag.py · Powercoder64/ffmpeg-python@861980d · GitHub
[go: up one dir, main page]

Skip to content

Commit 861980d

Browse files
committed
Simplify, expand and explain complicated loops in dag.py
1 parent 783bdbd commit 861980d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ffmpeg/dag.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def incoming_edge_map(self):
7575

7676
def get_incoming_edges(downstream_node, incoming_edge_map):
7777
edges = []
78-
for downstream_label, upstream_info in [(i[0], i[1]) for i in incoming_edge_map.items()]:
78+
for downstream_label, upstream_info in incoming_edge_map.items():
79+
# `upstream_info` may contain the upstream_selector. [:2] trims it away
7980
upstream_node, upstream_label = upstream_info[:2]
81+
# Take into account the stream selector if it's present (i.e. len(upstream_info) >= 3)
8082
upstream_selector = None if len(upstream_info) < 3 else upstream_info[2]
8183
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label, upstream_selector)]
8284
return edges
@@ -86,7 +88,9 @@ def get_outgoing_edges(upstream_node, outgoing_edge_map):
8688
edges = []
8789
for upstream_label, downstream_infos in list(outgoing_edge_map.items()):
8890
for downstream_info in downstream_infos:
91+
# `downstream_info` may contain the downstream_selector. [:2] trims it away
8992
downstream_node, downstream_label = downstream_info[:2]
93+
# Take into account the stream selector if it's present
9094
downstream_selector = None if len(downstream_info) < 3 else downstream_info[2]
9195
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label, downstream_selector)]
9296
return edges
@@ -99,8 +103,10 @@ class KwargReprNode(DagNode):
99103
@property
100104
def __upstream_hashes(self):
101105
hashes = []
102-
# This is needed to allow extra stuff in the incoming_edge_map's value tuples
103-
for downstream_label, (upstream_node, upstream_label) in [(i[0], i[1][:2]) for i in self.incoming_edge_map.items()]:
106+
for downstream_label, upstream_info in self.incoming_edge_map.items():
107+
# `upstream_info` may contain the upstream_selector. [:2] trims it away
108+
upstream_node, upstream_label = upstream_info[:2]
109+
# The stream selector is discarded when calculating the hash: the stream "as a whole" is still the same
104110
hashes += [hash(x) for x in [downstream_label, upstream_node, upstream_label]]
105111
return hashes
106112

0 commit comments

Comments
 (0)
0