Skip to content

Commit 8c65a79

Browse files
wanda-phiwhitequark
authored andcommitted
hdl._ir: Remove support for non-Elaboratable elaboratables.
Fixes #1216.
1 parent 2569886 commit 8c65a79

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

amaranth/hdl/_ir.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,8 @@ def get(obj, platform):
4545
UnusedElaboratable._MustUse__silence = False
4646
obj._MustUse__used = True
4747
new_obj = obj.elaborate(platform)
48-
elif hasattr(obj, "elaborate"):
49-
warnings.warn(
50-
message="Class {!r} is an elaboratable that does not explicitly inherit from "
51-
"Elaboratable; doing so would improve diagnostics"
52-
.format(type(obj)),
53-
category=RuntimeWarning,
54-
stacklevel=2)
55-
code = obj.elaborate.__code__
56-
new_obj = obj.elaborate(platform)
5748
else:
58-
raise AttributeError(f"Object {obj!r} cannot be elaborated")
49+
raise TypeError(f"Object {obj!r} is not an 'Elaboratable' nor 'Fragment'")
5950
if new_obj is obj:
6051
raise RecursionError(f"Object {obj!r} elaborates to itself")
6152
if new_obj is None and code is not None:

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Apply the following changes to code written against Amaranth 0.4 to migrate it t
3737
* Replace uses of ``amaranth.hdl.Memory`` with ``amaranth.lib.memory.Memory``
3838
* Replace imports of ``amaranth.asserts.{Assert, Assume, Cover}`` with imports from ``amaranth.hdl``
3939
* Remove any usage of ``name=`` with assertions, possibly replacing them with custom messages
40+
* Ensure all elaboratables are subclasses of :class:`Elaboratable`
4041

4142

4243
Implemented RFCs
@@ -89,6 +90,7 @@ Language changes
8990
* Removed: (deprecated in 0.4) :class:`Repl`. (`RFC 10`_)
9091
* Removed: (deprecated in 0.4) :class:`ast.Sample`, :class:`ast.Past`, :class:`ast.Stable`, :class:`ast.Rose`, :class:`ast.Fell`.
9192
* Removed: assertion names in :class:`Assert`, :class:`Assume` and :class:`Cover`. (`RFC 50`_)
93+
* Removed: accepting non-subclasses of :class:`Elaboratable` as elaboratables.
9294

9395

9496
Standard library changes

tests/test_hdl_ir.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def elaborate(self, platform):
2323

2424
class FragmentGetTestCase(FHDLTestCase):
2525
def test_get_wrong_none(self):
26-
with self.assertRaisesRegex(AttributeError,
27-
r"^Object None cannot be elaborated$"):
26+
with self.assertRaisesRegex(TypeError,
27+
r"^Object None is not an 'Elaboratable' nor 'Fragment'$"):
2828
Fragment.get(None, platform=None)
2929

3030
with self.assertWarnsRegex(UserWarning,
3131
r"^\.elaborate\(\) returned None; missing return statement\?$"):
32-
with self.assertRaisesRegex(AttributeError,
33-
r"^Object None cannot be elaborated$"):
32+
with self.assertRaisesRegex(TypeError,
33+
r"^Object None is not an 'Elaboratable' nor 'Fragment'$"):
3434
Fragment.get(ElaboratesToNone(), platform=None)
3535

3636
def test_get_wrong_self(self):

0 commit comments

Comments
 (0)