From 2d75a526b3087b778cf45292f7cd7c5340ef9378 Mon Sep 17 00:00:00 2001 From: Robin Ole Heinemann Date: Fri, 20 Sep 2024 14:35:22 +0200 Subject: [PATCH] lib.wiring: Add path argument to Component constructor --- amaranth/lib/wiring.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/amaranth/lib/wiring.py b/amaranth/lib/wiring.py index 1122a625f..d1b9bed7c 100644 --- a/amaranth/lib/wiring.py +++ b/amaranth/lib/wiring.py @@ -1648,6 +1648,9 @@ def __init__(self, data_width): constructor creates attributes corresponding to all of the members defined in the signature. If an attribute with the same name as that of a member already exists, an error is raied. + By default all members defined in the signature are created with a :py:`path` of :py:`()`. + This can be overwritten using the :py:`path` keyword argument of the superclass constructor. + Raises ------ :exc:`TypeError` @@ -1658,7 +1661,7 @@ def __init__(self, data_width): If a name conflict is detected between two variable annotations, or between a member and an existing attribute. """ - def __init__(self, signature=None, *, src_loc_at=0): + def __init__(self, signature=None, *, path=(), src_loc_at=0): cls = type(self) members = {} for base in reversed(cls.mro()[:cls.mro().index(Component)]): @@ -1692,7 +1695,7 @@ def __init__(self, signature=None, *, src_loc_at=0): if hasattr(self, name): raise NameError(f"Cannot initialize attribute for signature member {name!r} " f"because an attribute with the same name already exists") - self.__dict__.update(signature.members.create(path=(), src_loc_at=src_loc_at + 1)) + self.__dict__.update(signature.members.create(path=path, src_loc_at=src_loc_at + 1)) @property def signature(self):