You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
I'm personally not convinced that's the right behavior, because it can lead to hard-to-debug issues
Yep, that's really unfortunate. In real code, these things can be far more subtle. The root cause in our case was a missing @property decorator as seen below.
classTestCase():
@propertydefis_running(self) ->bool:
returnnotself.is_stoppedandself.meh()
#@property # <-- if we forget the @property, the missing `meh` goes unnoticeddefis_stopped(self) ->bool:
returnFalse
If you add the property decorator, mypy will rightfully catch the missing meh() method but if you forget the property, the missing method just goes unnoticed.
Activity
JelleZijlstra commentedon Jun 13, 2019
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.
cburgdorf commentedon Jun 14, 2019
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
@propertydecorator as seen below.If you add the
propertydecorator, mypy will rightfully catch the missingmeh()method but if you forget the property, the missing method just goes unnoticed.ilevkivskyi commentedon Jun 15, 2019
One of the possible ways forward is to emit an error/warning when mypy skips some branch because it is unreachable, see #2395
ilevkivskyi commentedon Jun 17, 2019
Now that we have a dedicated issue #7008, I think we can close this as a duplicate.