Skip to content

Commit bba4235

Browse files
committed
hdl.ast: bring new naming rules to IOPort
1 parent 0f02b80 commit bba4235

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

amaranth/hdl/_ast.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2824,8 +2824,7 @@ class IOPort(IOValue):
28242824
def __init__(self, width, *, name=None, attrs=None, metadata=None, src_loc_at=0):
28252825
super().__init__(src_loc_at=src_loc_at)
28262826

2827-
if name is not None and not isinstance(name, str):
2828-
raise TypeError(f"Name must be a string, not {name!r}")
2827+
validate_name(name, "Name", none_ok=True)
28292828
self.name = name or tracer.get_var_name(depth=2 + src_loc_at)
28302829

28312830
self._width = operator.index(width)

tests/test_hdl_ast.py

+3
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,9 @@ def test_ioport(self):
17321732
self.assertEqual(b.metadata, ("x", "y", "z"))
17331733
self.assertEqual(b._ioports(), {b})
17341734
self.assertRepr(b, "(io-port b)")
1735+
with self.assertRaisesRegex(NameError,
1736+
r"^Name must be a non-empty string$"):
1737+
IOPort(1, name="")
17351738

17361739
def test_ioport_wrong(self):
17371740
with self.assertRaisesRegex(TypeError,

0 commit comments

Comments
 (0)