Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError caused by UnusedElaboratable after an elaboratable has failed its initialization #1382

Open
jfng opened this issue Jun 14, 2024 · 1 comment

Comments

@jfng
Copy link
Member

jfng commented Jun 14, 2024

Repro:

from amaranth import *
from amaranth.lib import wiring
from amaranth.hdl import Fragment


class Foo(wiring.Component):
    def __init__(self, arg):
        if not isinstance(arg, int):
            raise TypeError
        self._arg = arg
        super().__init__({})

    def elaborate(self, platform):
        return Module()

    def __repr__(self):
        return f"Foo({self._arg!r})"


Fragment.get(Foo(1), None)
try:
    Foo("fail")
except TypeError:
    pass

Output:

# Exception ignored in: <function MustUse.__del__ at 0x7f8410a2d440>
# Traceback (most recent call last):
#   File ".../python3.12/site-packages/amaranth/_unused.py", line 37, in __del__
#     f"{self!r} created but never used", self._MustUse__warning,
#       ^^^^^^^^
#   File "/tmp/repro.py", line 17, in __repr__
#     return f"Foo({self._arg!r})"
#                   ^^^^^^^^^
# AttributeError: 'Foo' object has no attribute '_arg'
@jfng
Copy link
Member Author

jfng commented Jun 14, 2024

This scenario is likely to only happen in unit tests, which can avoid it with a # amaranth: UnusedElaboratable=no modeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants