-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Mypy incorrectly says signature is incompatible with supertype when using decorator #3260
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
I played with this a bit and it looks like this is specific to |
I just ran into this too with a method decorated with |
I also ran with this issue today, precisely with the @lry_cache decorator on a subclass's method overriding a base method. Are there any solutions or workarounds at this point? |
I' ve als got this issue with a stub-file for PyQt5:
Results in the following mypy error:
|
@stlehmann Mypy is right in your case, it fails Liskov. The subclass method requires more arguments than the superclass method, so it is not a proper subtype. |
@stlehmann You can silence the mypy error by adding a |
@gvanrossum Thanks for the explanation. I googled Liskov and it makes perfectly sense. However in this case I can't change the API so I will use |
We should put this somewhere in the docs.
|
I tried both examples ( |
I'm not sure the I found this when I had defined an
results in:
|
Yes, this is a bug, but we already have an issue for this, see #5836 |
Ok, cool. I'll follow along there, thanks! 5:) |
I am still encountering this issue with the following use case on MyPy version 0.991: from functools import cache
class Base:
@classmethod
@cache
def value(cls) -> str:
# Some expensive default implementation
return "[computed default]"
class Simple(Base):
@classmethod
def value(cls) -> str:
return "Simple value that doesn't need caching"
|
When checking the code below with mypy v0.501, mypy complains that
According to @ilevkivskyi this may be related to #1441.
The text was updated successfully, but these errors were encountered: