Skip to content

Commit 72c802b

Browse files
committed
hdl.ast: bring new naming rules to IOPort
1 parent a5f4c53 commit 72c802b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

amaranth/hdl/_ast.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,8 +2847,7 @@ class IOPort(IOValue):
28472847
def __init__(self, width, *, name=None, attrs=None, metadata=None, src_loc_at=0):
28482848
super().__init__(src_loc_at=src_loc_at)
28492849

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

28542853
self._width = operator.index(width)

tests/test_hdl_ast.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,9 @@ def test_ioport(self):
17421742
self.assertEqual(b.metadata, ("x", "y", "z"))
17431743
self.assertEqual(b._ioports(), {b})
17441744
self.assertRepr(b, "(io-port b)")
1745+
with self.assertRaisesRegex(NameError,
1746+
r"^Name must be a non-empty string$"):
1747+
IOPort(1, name="")
17451748

17461749
def test_ioport_wrong(self):
17471750
with self.assertRaisesRegex(TypeError,

0 commit comments

Comments
 (0)