hdl._ast: make Shape immutable and hashable.

Fixes #1127.
This commit is contained in:
Wanda 2024-02-16 15:27:27 +01:00 committed by Catherine
parent 24a392887a
commit 6058ad35cf
3 changed files with 24 additions and 2 deletions

View file

@ -152,6 +152,16 @@ class ShapeTestCase(FHDLTestCase):
r"^Object 'foo' cannot be converted to an Amaranth shape$"):
Shape.cast("foo")
def test_hashable(self):
d = {
signed(2): "a",
unsigned(3): "b",
unsigned(2): "c",
}
self.assertEqual(d[signed(2)], "a")
self.assertEqual(d[unsigned(3)], "b")
self.assertEqual(d[unsigned(2)], "c")
class MockShapeCastable(ShapeCastable):
def __init__(self, dest):