-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Teach mypy about NoReturn #2798
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
Conversation
One thing this doesn't do is disallow use of |
Looks good! It would be good to have more test cases. Here are some ideas:
If some of these are non-trivial to support, you can create new issues for these. |
I'm not sure I agree that using Added tests for the last two bullets. |
I'd say that for the first three bullets, the expression containing the call itself inherits the "doesn't return" property. So then this should lead to some dead code, depending on the control flow. E.g. here I'd expect the final line of the function to be unreachable (given the above definition of def f() -> int:
no_return()
does_not_exist() # Not a NameError because it's unreachable I don't feel to strongly about all this though, so I personally am fine with however you and Jukka decide this. |
Currently we don't check for unreachable code, though. E.g. def f() -> None:
return
does_not_exist() # E: Name 'does_not_exist' is not defined |
Agreed that some of the cases I listed aren't real type errors, but they are at least pretty questionable and likely signs of code quality issues. I don't expect those cases to be common in the wild, so the current behavior is already okay. (We already reject arguably similar cases, such as using the return value of a function with a |
Fixes #2474.