Skip to content

lib.io: Add missing __repr__ to signature type. #1167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions amaranth/lib/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def __eq__(self, other):
self.dir == other.dir and
self.xdr == other.xdr)

def __repr__(self):
xdr = f", xdr={self.xdr}" if self.xdr != 0 else ""
return f"Pin.Signature({self.width}, dir={self.dir!r}{xdr})"

def create(self, *, path=None, src_loc_at=0):
return Pin(self.width, self.dir, xdr=self.xdr, path=path, src_loc_at=1 + src_loc_at)

Expand All @@ -128,11 +132,11 @@ def __init__(self, width, dir, *, xdr=0, name=None, path=None, src_loc_at=0):
@property
def width(self):
return self.signature.width

@property
def dir(self):
return self.signature.dir

@property
def xdr(self):
return self.signature.xdr
11 changes: 10 additions & 1 deletion tests/test_lib_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ def test_signature_io(self):
})


class PinSignatureReprCase(FHDLTestCase):
def test_repr(self):
sig_0 = Pin.Signature(1, dir="i")
self.assertRepr(sig_0, "Pin.Signature(1, dir='i')")
sig_0 = Pin.Signature(2, dir="o", xdr=1)
self.assertRepr(sig_0, "Pin.Signature(2, dir='o', xdr=1)")
sig_0 = Pin.Signature(3, dir="io", xdr=2)
self.assertRepr(sig_0, "Pin.Signature(3, dir='io', xdr=2)")


class PinTestCase(FHDLTestCase):
def test_attributes(self):
pin = Pin(2, dir="io", xdr=2)
Expand All @@ -208,4 +218,3 @@ def test_attributes(self):
self.assertEqual(pin.signature.width, 2)
self.assertEqual(pin.signature.dir, "io")
self.assertEqual(pin.signature.xdr, 2)