Skip to content

Commit 557122c

Browse files
committed
Look-up mated connectors before mate processing (#358)
Symptom reported in #355: Unable to connect an arrow (mate) to pins higher than 1 without failing: ValueError: X is not in list Bug: The code processing mates used a mix of repeated connector look-ups and local connector variables, and one variable was used before it was assigned the correct value. Fix: The local connector variables are now both assigned initially before processing each mate, and used when processing instead of repeated connector look-ups.
1 parent a89d04d commit 557122c

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

src/wireviz/Harness.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ def typecheck(name: str, value: Any, expect: type) -> None:
595595
typecheck("tweak.append", self.tweak.append, str)
596596
dot.body.append(self.tweak.append)
597597

598+
# TODO: All code below until "return dot" must be moved above all tweak processing!
598599
for mate in self.mates:
599600
if mate.shape[0] == "<" and mate.shape[-1] == ">":
600601
dir = "both"
@@ -613,29 +614,18 @@ def typecheck(name: str, value: Any, expect: type) -> None:
613614
raise Exception(f"{mate} is an unknown mate")
614615

615616
from_connector = self.connectors[mate.from_name]
616-
if (
617-
isinstance(mate, MatePin)
618-
and self.connectors[mate.from_name].style != "simple"
619-
):
617+
to_connector = self.connectors[mate.to_name]
618+
if isinstance(mate, MatePin) and from_connector.style != "simple":
620619
from_pin_index = from_connector.pins.index(mate.from_pin)
621620
from_port_str = f":p{from_pin_index+1}r"
622621
else: # MateComponent or style == 'simple'
623622
from_port_str = ""
624-
if (
625-
isinstance(mate, MatePin)
626-
and self.connectors[mate.to_name].style != "simple"
627-
):
623+
if isinstance(mate, MatePin) and to_connector.style != "simple":
628624
to_pin_index = to_connector.pins.index(mate.to_pin)
629-
to_port_str = (
630-
f":p{to_pin_index+1}l"
631-
if isinstance(mate, MatePin)
632-
and self.connectors[mate.to_name].style != "simple"
633-
else ""
634-
)
625+
to_port_str = f":p{to_pin_index+1}l"
635626
else: # MateComponent or style == 'simple'
636627
to_port_str = ""
637628
code_from = f"{mate.from_name}{from_port_str}:e"
638-
to_connector = self.connectors[mate.to_name]
639629
code_to = f"{mate.to_name}{to_port_str}:w"
640630

641631
dot.attr("edge", color=color, style="dashed", dir=dir)

0 commit comments

Comments
 (0)