Skip to content

Commit

Permalink
Replace if-elif chain with match-case for rendering node
Browse files Browse the repository at this point in the history
  • Loading branch information
enourbakhsh committed Jan 9, 2025
1 parent 8b3be62 commit 567731f
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,19 @@ def show_mermaid(

# Render nodes.
for node_key, node_data in xgraph.nodes.items():
if node_key.node_type in (NodeType.TASK, NodeType.TASK_INIT):
# Render a task or task-init node.
_render_task_node(node_key, node_data, options, stream)
elif node_key.node_type == NodeType.DATASET_TYPE:
# Render a dataset-type node with possible overflow handling.
overflow_ref, node_overflow_ids = _render_dataset_type_node(
node_key, node_data, options, stream, overflow_ref
)
if node_overflow_ids:
overflow_ids.extend(node_overflow_ids)
else:
raise AssertionError(f"Unexpected node type: {node_key.node_type}")
match node_key.node_type:

Check warning on line 118 in python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py#L118

Added line #L118 was not covered by tests
case NodeType.TASK | NodeType.TASK_INIT:
# Render a task or task-init node.
_render_task_node(node_key, node_data, options, stream)

Check warning on line 121 in python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py#L121

Added line #L121 was not covered by tests
case NodeType.DATASET_TYPE:
# Render a dataset-type node with possible overflow handling.
overflow_ref, node_overflow_ids = _render_dataset_type_node(

Check warning on line 124 in python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py#L124

Added line #L124 was not covered by tests
node_key, node_data, options, stream, overflow_ref
)
if node_overflow_ids:
overflow_ids += node_overflow_ids
case _:

Check warning on line 129 in python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/pipeline_graph/visualization/_mermaid.py#L128-L129

Added lines #L128 - L129 were not covered by tests
raise AssertionError(f"Unexpected node type: {node_key.node_type}")

# Collect edges for printing and track which ones are prerequisite
# so we can apply dashed styling after printing them.
Expand Down

0 comments on commit 567731f

Please sign in to comment.