Skip to content

Commit b9dc4d3

Browse files
committed
lib.io: fix representation of empty SingleEndedPort.
Before this commit, any such port would be displayed as `invert=True`, which is confusing if the original port had no inversion. `DifferentialPort` is unaffected.
1 parent 87be5e1 commit b9dc4d3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

amaranth/lib/io.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ def __add__(self, other):
203203
direction=self._direction & other._direction)
204204

205205
def __repr__(self):
206-
if all(self._invert):
207-
invert = True
208-
elif not any(self._invert):
206+
if not any(self._invert):
209207
invert = False
208+
elif all(self._invert):
209+
invert = True
210210
else:
211211
invert = self._invert
212212
return f"SingleEndedPort({self._io!r}, invert={invert!r}, direction={self._direction})"

tests/test_lib_io.py

+13
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ def test_invert(self):
8888
iport = ~port
8989
self.assertRepr(iport, "SingleEndedPort((io-port io), invert=(False, True, False, True), direction=Direction.Output)")
9090

91+
def test_empty(self):
92+
io = IOPort(1)
93+
port = SingleEndedPort(io, invert=False)
94+
eport = port[0:0]
95+
self.assertRepr(eport, "SingleEndedPort((io-slice (io-port io) 0:0), invert=False, direction=Direction.Bidir)")
96+
9197

9298
class DifferentialPortTestCase(FHDLTestCase):
9399
def test_construct(self):
@@ -160,6 +166,13 @@ def test_invert(self):
160166
iport = ~port
161167
self.assertRepr(iport, "DifferentialPort((io-port iop), (io-port ion), invert=(False, True, False, True), direction=Direction.Output)")
162168

169+
def test_empty(self):
170+
iop = IOPort(1)
171+
ion = IOPort(1)
172+
port = DifferentialPort(iop, ion, invert=False)
173+
eport = port[0:0]
174+
self.assertRepr(eport, "DifferentialPort((io-slice (io-port iop) 0:0), (io-slice (io-port ion) 0:0), invert=False, direction=Direction.Bidir)")
175+
163176

164177
class BufferTestCase(FHDLTestCase):
165178
def test_signature(self):

0 commit comments

Comments
 (0)