lib.wiring: fix __repr__ for PureInterface subclasses.

Fixes #988.
This commit is contained in:
Catherine 2023-12-05 04:40:16 +00:00
parent 0cdcab0fbb
commit 120375dabe
2 changed files with 7 additions and 1 deletions

View file

@ -611,7 +611,7 @@ class PureInterface:
attrs = ''.join(f", {name}={value!r}" attrs = ''.join(f", {name}={value!r}"
for name, value in self.__dict__.items() for name, value in self.__dict__.items()
if name != "signature") if name != "signature")
return f'<PureInterface: {self.signature}{attrs}>' return f'<{type(self).__name__}: {self.signature}{attrs}>'
# To reduce API surface area `FlippedInterface` is made final. This restriction could be lifted # To reduce API surface area `FlippedInterface` is made final. This restriction could be lifted

View file

@ -671,6 +671,12 @@ class PureInterfaceTestCase(unittest.TestCase):
intf = PureInterface(sig, path=("test",)) intf = PureInterface(sig, path=("test",))
self.assertEqual(repr(intf), "<PureInterface: Signature({'a': In(4), 'b': Out(signed(2))}), a=(sig test__a), b=(sig test__b)>") self.assertEqual(repr(intf), "<PureInterface: Signature({'a': In(4), 'b': Out(signed(2))}), a=(sig test__a), b=(sig test__b)>")
def test_repr_inherit(self):
class CustomInterface(PureInterface):
pass
intf = CustomInterface(Signature({}), path=())
self.assertRegex(repr(intf), r"^<CustomInterface: .+?>$")
class FlippedInterfaceTestCase(unittest.TestCase): class FlippedInterfaceTestCase(unittest.TestCase):
def test_basic(self): def test_basic(self):