Skip to content

False-positive error on overriding attribute of base class with rtype-annotated property  #9134

Closed
@sizmailov

Description

@sizmailov

(bug report)

Annotation of property of derived class with -> Any makes mypy complain about incompatibility with base class. The exact rtype doesn't matter, the error is still the same. The MRE is a simplified version of stubgen output.

MRE:

from typing import Any

class A:
    doc = ""

class B(A):
    # remove "-> Any" to make mypy happy
    @property
    def doc(self) -> Any:
        return ""

Expected: no errors reported

Actual:

foo.py:11: error: Signature of "doc" incompatible with supertype "A"
Found 1 error in 1 file (checked 1 source file)

command line command: mypy foo.py

version info:
mypy: 0.790+dev.ffdbeb3d47ccb2d9691b36993be0a18e0718d997
python: 3.7.3

P.S.: The error message of Signature of "doc" incompatible with supertype "A" should be more descriptive. It's good enough for simple cases, but rather cryptic for more involved examples. (I realize it might be not so trivial to propagate the root source of incompatibility and represent it nicely)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions