mypy icon indicating copy to clipboard operation
mypy copied to clipboard

no error when overriding property with incompatible return type when the overridden property has a setter that's decorated with a `contextmanager`

Open DetachHead opened this issue 1 year ago • 0 comments

from contextlib import contextmanager
from typing import Iterator

@contextmanager
def foo() -> Iterator[None]:
    yield


class Bar:
    @property
    def asdf(self) -> int:
        return 2


class Baz(Bar):
    @property
    def asdf(self) -> str: # no error
        return ""

    @asdf.setter
    @foo()
    def asdf(self, new_value): ...

playground

removing the @foo() decorator makes the error appear:

main.py:16: error: Signature of "asdf" incompatible with supertype "Bar"  [override]
main.py:16: note:      Superclass:
main.py:16: note:          int
main.py:16: note:      Subclass:
main.py:16: note:          str
Found 1 error in 1 file (checked 1 source file)

DetachHead avatar Jun 17 '24 05:06 DetachHead