From 697e7d76c411d2321c27c6c6c0b993a488b6c6d0 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Mon, 4 Mar 2024 14:38:18 +0000 Subject: [PATCH] feat: don't include empty type args in Display (#857) --- .../snapshots/hugr__hugr__views__tests__dot_string.snap | 2 +- src/types.rs | 3 +-- src/types/custom.rs | 6 +++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap b/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap index 6a166f9a3..2a04e5b4e 100644 --- a/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap +++ b/src/hugr/views/snapshots/hugr__hugr__views__tests__dot_string.snap @@ -2,5 +2,5 @@ source: src/hugr/views/tests.rs expression: h.dot_string() --- -"digraph {\n0 [shape=plain label=<
(0) DFG
>]\n1 [shape=plain label=<
(1) Input
0: qubit([])1: qubit([])
>]\n1:out0 -> 3:in0 [style=\"\"]\n1:out1 -> 3:in1 [style=\"\"]\n2 [shape=plain label=<
0: qubit([])1: qubit([])
(2) Output
>]\n3 [shape=plain label=<
0: qubit([])1: qubit([])
(3) test.quantum.CX
0: qubit([])1: qubit([])
>]\n3:out0 -> 4:in1 [style=\"\"]\n3:out1 -> 4:in0 [style=\"\"]\n3:out2 -> 4:in2 [style=\"dotted\"]\n4 [shape=plain label=<
0: qubit([])1: qubit([])
(4) test.quantum.CX
0: qubit([])1: qubit([])
>]\n4:out0 -> 2:in0 [style=\"\"]\n4:out1 -> 2:in1 [style=\"\"]\nhier0 [shape=plain label=\"0\"]\nhier0 -> hier1 [style = \"dashed\"] \nhier0 -> hier2 [style = \"dashed\"] \nhier0 -> hier3 [style = \"dashed\"] \nhier0 -> hier4 [style = \"dashed\"] \nhier1 [shape=plain label=\"1\"]\nhier2 [shape=plain label=\"2\"]\nhier3 [shape=plain label=\"3\"]\nhier4 [shape=plain label=\"4\"]\n}\n" +"digraph {\n0 [shape=plain label=<
(0) DFG
>]\n1 [shape=plain label=<
(1) Input
0: qubit1: qubit
>]\n1:out0 -> 3:in0 [style=\"\"]\n1:out1 -> 3:in1 [style=\"\"]\n2 [shape=plain label=<
0: qubit1: qubit
(2) Output
>]\n3 [shape=plain label=<
0: qubit1: qubit
(3) test.quantum.CX
0: qubit1: qubit
>]\n3:out0 -> 4:in1 [style=\"\"]\n3:out1 -> 4:in0 [style=\"\"]\n3:out2 -> 4:in2 [style=\"dotted\"]\n4 [shape=plain label=<
0: qubit1: qubit
(4) test.quantum.CX
0: qubit1: qubit
>]\n4:out0 -> 2:in0 [style=\"\"]\n4:out1 -> 2:in1 [style=\"\"]\nhier0 [shape=plain label=\"0\"]\nhier0 -> hier1 [style = \"dashed\"] \nhier0 -> hier2 [style = \"dashed\"] \nhier0 -> hier3 [style = \"dashed\"] \nhier0 -> hier4 [style = \"dashed\"] \nhier1 [shape=plain label=\"1\"]\nhier2 [shape=plain label=\"2\"]\nhier3 [shape=plain label=\"3\"]\nhier4 [shape=plain label=\"4\"]\n}\n" diff --git a/src/types.rs b/src/types.rs index aaf616354..4cc5e895c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -422,8 +422,7 @@ pub(crate) mod test { ]); assert_eq!( t.to_string(), - "Tuple([usize([]), Function(forall . [[]][]), my_custom([]), Alias(my_alias)])" - .to_string() + "Tuple([usize, Function(forall . [[]][]), my_custom, Alias(my_alias)])".to_string() ); } diff --git a/src/types/custom.rs b/src/types/custom.rs index 2224b7325..50e112502 100644 --- a/src/types/custom.rs +++ b/src/types/custom.rs @@ -124,6 +124,10 @@ impl CustomType { impl Display for CustomType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}({:?})", self.id, self.args) + if self.args.is_empty() { + write!(f, "{}", self.id) + } else { + write!(f, "{}({:?})", self.id, self.args) + } } }