-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Mypy does not recognize missing method #6990
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
Mypy doesn't type check code it thinks is unreachable. I'm personally not convinced that's the right behavior, because it can lead to hard-to-debug issues, but that's probably not something we can easily change. |
Hey @JelleZijlstra thank you for your prompt reply!
Yep, that's really unfortunate. In real code, these things can be far more subtle. The root cause in our case was a missing class TestCase():
@property
def is_running(self) -> bool:
return not self.is_stopped and self.meh()
#@property # <-- if we forget the @property, the missing `meh` goes unnoticed
def is_stopped(self) -> bool:
return False If you add the |
One of the possible ways forward is to emit an error/warning when mypy skips some branch because it is unreachable, see #2395 |
Now that we have a dedicated issue #7008, I think we can close this as a duplicate. |
In the following example, mypy does not catch that
self.meh()
does not exist. Is this expected behavior because of the staticFalse
?The original bug in our code base was harder to spot than this but it boils down to the same reason so I'm wondering if this is expected behavior.
If I change the example to
then
mypy
does in fact spot the missingmeh
method.The text was updated successfully, but these errors were encountered: