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
Detect unreachable except
branches
#11514
Comments
Great idea! |
If possible, I'd be interested in hacking on this as an interesting side project. I took a scan through the code and couldn't figure out where such an analysis pass might fit in to mypy. If this seems like a reasonable project for someone who's new-to-mypy-but-not-new-to-python, I'd welcome some advice on where/how this feature should be added. "No, this is a tricky feature that would be best handled by the core mypy team" is also a fine response. Happy to help if possible. |
@jcrist yes, this looks rather simple. I can guide you, if you wish 🙂 So, here's how I see this:
I hope that this helps. Feel free to ping me if you have any questions 🙂 |
@jcrist are you still working on this? If not I would give it a try :) |
No, I never gave it a go - please feel free to pick this up. |
Since except blocks are checked in order, and the first matching block is executed, it's possible to accidentally write a try-except that will never execute some branches. For example:
Since
PermissionError
is a subclass ofOSError
, theexcept PermissionError
case will never execute. I'd expect/hope that these kind of mistakes would be detectable with type information. I think adding checks for this would make sense under the--warn-unreachable
config flag, so a new CLI option may not be needed.The text was updated successfully, but these errors were encountered: