-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
False-positive error on overriding attribute of base class with rtype-annotated property #9134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The error message is kind of reasonable, since
I think that mypy sometimes produces a better message, but not in this case. Would you like to create a separate issue about the better error message? |
If it so, the next snippet should pass the check, right? from typing import Any
class A:
doc = ""
class B(A):
@property
def doc(self) -> Any:
return ""
@doc.setter
def doc(self, value: str) -> None:
print("set")
@doc.deleter
def doc(self) -> None:
print("del") In fact
At the moment I'm not sure what makes |
Apparently Another form of overriding value-attribute with class B(A):
doc = property(...)
# Incompatible types in assignment (expression has type "property", base class "A" defined the type as "str") Same applies to custom descriptors as well: class B(A):
doc = RevealAccess(10, 'var "x"')
# Incompatible types in assignment (expression has type "RevealAccess", base class "A" defined the type as "str") |
Now mypy gives a nice error
and passes when setter is added. |
(bug report)
Annotation of property of derived class with
-> Any
makesmypy
complain about incompatibility with base class. The exact rtype doesn't matter, the error is still the same. The MRE is a simplified version ofstubgen
output.MRE:
Expected: no errors reported
Actual:
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)The text was updated successfully, but these errors were encountered: