diff --git a/amaranth/lib/wiring.py b/amaranth/lib/wiring.py index 624d98a..f5b70c9 100644 --- a/amaranth/lib/wiring.py +++ b/amaranth/lib/wiring.py @@ -607,6 +607,12 @@ class Interface: **signature.members.create(path=path) }) + def __repr__(self): + attrs = ''.join(f", {name}={value!r}" + for name, value in self.__dict__.items() + if name != "signature") + return f'' + # To reduce API surface area `FlippedInterface` is made final. This restriction could be lifted # if there is a compelling use case. diff --git a/tests/test_lib_wiring.py b/tests/test_lib_wiring.py index 2ee96c2..41da9e3 100644 --- a/tests/test_lib_wiring.py +++ b/tests/test_lib_wiring.py @@ -653,7 +653,23 @@ class FlippedSignatureTestCase(unittest.TestCase): class InterfaceTestCase(unittest.TestCase): - pass + def test_construct(self): + sig = Signature({ + "a": In(4), + "b": Out(signed(2)), + }) + intf = Interface(sig, path=("test",)) + self.assertIs(intf.signature, sig) + self.assertIsInstance(intf.a, Signal) + self.assertIsInstance(intf.b, Signal) + + def test_repr(self): + sig = Signature({ + "a": In(4), + "b": Out(signed(2)), + }) + intf = Interface(sig, path=("test",)) + self.assertEqual(repr(intf), "") class FlippedInterfaceTestCase(unittest.TestCase): @@ -666,7 +682,7 @@ class FlippedInterfaceTestCase(unittest.TestCase): self.assertEqual(tintf.signature, intf.signature.flip()) self.assertEqual(tintf, flipped(intf)) self.assertRegex(repr(tintf), - r"^flipped\(<.+?\.Interface object at .+>\)$") + r"^flipped\(\)$") self.assertIs(flipped(tintf), intf) def test_getsetdelattr(self):