Pylance: "property" is incompatible with "int"

Viewed 184
from typing_extensions import Protocol


class IFoo(Protocol):
    value: int


class Foo(IFoo):
    @property
    def value(self) -> int:
        return 2

    _value: int

    @value.setter
    def value(self, value: int):
        self._value = value

Pylance in strict mode(basic mode doesn't) is giving an error at the getter and the setter saying that:

"value" overrides symbol of the same name in class "IFoo" "property" is incompatible with "int".

I could make this work by changing the Protocol to:

class IFoo(Protocol):
    @property
    def value(self) -> int:
        raise NotImplemented

But this now makes this invalid:

class Foo(IFoo):
    value: int

This doesn't makes sense, the Foo would still have the property value that is an int, why being a getter should makes it different (in typescript this doesn't make a difference)? How can I fix this?

0 Answers
Related