amaranth icon indicating copy to clipboard operation
amaranth copied to clipboard

Pyright errors on `m.[If/Elif/Else]`: No `__enter__` or `__exit__`

Open turtlebasket opened this issue 1 year ago • 1 comments

Hello! Reporting a Pyright error with Module.If/Else/Elif. This is reproducible with the following example:

from amaranth import *


class Thing(Elaboratable):
    def __init__(self) -> None:
        self.a = Signal(Shape(1))
        self.b = Signal(unsigned(8))

    def elaborate(self, platform) -> Module:
        m = Module()
        with m.If(self.a == 0):
            m.d.sync += self.b.eq(12)
        with m.Elif(self.a == 1):
            m.d.sync += self.b.eq(34)
        with m.Else():
            m.d.sync += self.a.eq(0)
        return m

...which yields the following:

Screenshot 2024-04-11 at 4 35 10 PM

Using:

  • pyright 1.1.344
  • amaranth 0.4.5
  • python 3.12.2

Note that:

  • The above example does emit valid verilog- the lack of __enter__ and __exit__ here just triggers type errors with Pyright.
  • I haven't observed this happening with Switch/Case or others.

turtlebasket avatar Apr 11 '24 23:04 turtlebasket

That's expected. Amaranth isn't currently type-checker-clean for downstream code and we don't yet have that scheduled on our roadmap.

whitequark avatar Apr 11 '24 23:04 whitequark