The default __repr__() from typing.NamedTuple does not include
the module name, so the replacement (which uses the preferred syntax
for specifying these shapes) doesn't either.
return Shape(width, signed)
raise TypeError("Object {!r} cannot be used as value shape".format(obj))
+ def __repr__(self):
+ if self.signed:
+ return "signed({})".format(self.width)
+ else:
+ return "unsigned({})".format(self.width)
+
# TODO: use dataclasses instead of this hack
def _Shape___init__(self, width=1, signed=False):
msg="Width must be a non-negative integer, not -1"):
Shape(-1)
+ def test_repr(self):
+ self.assertEqual(repr(Shape()), "unsigned(1)")
+ self.assertEqual(repr(Shape(2, True)), "signed(2)")
+
def test_tuple(self):
width, signed = Shape()
self.assertEqual(width, 1)