equinox icon indicating copy to clipboard operation
equinox copied to clipboard

AbstractVar implemented as property wrongly appears in default init signature

Open danielward27 opened this issue 3 months ago • 1 comments

To be honest, I've mostly avoided this pattern by making things attributes, but, just to report:


import equinox as eqx


class AbstractClass(eqx.Module):
    a: eqx.AbstractVar[int]


class MyClass(AbstractClass):
    @property
    def a(self) -> int:
        return 1


# Pyright: Argument missing for parameter a
MyClass()  # LSP signature hint: (a: AbstractVar[int]) -> MyClass

danielward27 avatar Oct 19 '25 09:10 danielward27

Ah, I'm aware of this. The workaround is to explicitly define a custom MyClass.__init__ method. Unfortunately I don't know of a good way to fool the typechecker on this one. (In particular, statically pretending that it is a ClassVar does not work due to https://github.com/microsoft/pyright/issues/4965.)

patrick-kidger avatar Oct 19 '25 10:10 patrick-kidger