Skip to content

Commit 1dd2e61

Browse files
wanda-phiwhitequark
authored andcommitted
lib.io: Add missing __repr__ to signature type.
1 parent 8af9fe2 commit 1dd2e61

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

amaranth/lib/io.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ def __eq__(self, other):
114114
self.dir == other.dir and
115115
self.xdr == other.xdr)
116116

117+
def __repr__(self):
118+
xdr = f", xdr={self.xdr}" if self.xdr != 0 else ""
119+
return f"Pin.Signature({self.width}, dir={self.dir!r}{xdr})"
120+
117121
def create(self, *, path=None, src_loc_at=0):
118122
return Pin(self.width, self.dir, xdr=self.xdr, path=path, src_loc_at=1 + src_loc_at)
119123

@@ -128,11 +132,11 @@ def __init__(self, width, dir, *, xdr=0, name=None, path=None, src_loc_at=0):
128132
@property
129133
def width(self):
130134
return self.signature.width
131-
135+
132136
@property
133137
def dir(self):
134138
return self.signature.dir
135-
139+
136140
@property
137141
def xdr(self):
138142
return self.signature.xdr

tests/test_lib_io.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ def test_signature_io(self):
199199
})
200200

201201

202+
class PinSignatureReprCase(FHDLTestCase):
203+
def test_repr(self):
204+
sig_0 = Pin.Signature(1, dir="i")
205+
self.assertRepr(sig_0, "Pin.Signature(1, dir='i')")
206+
sig_0 = Pin.Signature(2, dir="o", xdr=1)
207+
self.assertRepr(sig_0, "Pin.Signature(2, dir='o', xdr=1)")
208+
sig_0 = Pin.Signature(3, dir="io", xdr=2)
209+
self.assertRepr(sig_0, "Pin.Signature(3, dir='io', xdr=2)")
210+
211+
202212
class PinTestCase(FHDLTestCase):
203213
def test_attributes(self):
204214
pin = Pin(2, dir="io", xdr=2)
@@ -208,4 +218,3 @@ def test_attributes(self):
208218
self.assertEqual(pin.signature.width, 2)
209219
self.assertEqual(pin.signature.dir, "io")
210220
self.assertEqual(pin.signature.xdr, 2)
211-

0 commit comments

Comments
 (0)