-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Potential false positive error of "Missing return statement" with Optional[NoReturn] typehint #9312
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
Separately, what does Optional[NoReturn] even mean? It may not return??? That seems outside of the intended use case for NoReturn. |
I do agree that it's outside of the intended use case. Here's why I used it: I think a type hint of
Also, it informs mypy that the method may return I think that a docstring is probably a superior way of communicating the method's intended behavior, but at least mypy knows half of what the method does. Feel free to follow up! :) |
You can use the mypy option Since basically anything in Python can raise an exception, using More generally, mypy's type system doesn't support checked exceptions (and is unlikely to do so), although there's some discussion in #1773 and others. |
I am a big fan of mypy, and have learned a ton about static type checking through mypy. I have a suggestion of a potential improvement.
I have what I think is a false positive error when using the type hint
Optional[NoReturn]
. Please see the below code sample.Running
mypy
yields:IMO, using the type hint
Optional
should not require one to type outreturn None
. It should be implied thatNone
will be returned if noreturn
statement is included.I think mypy should not report "Missing return statement" in this case. Let me know what you think!
Versions
The text was updated successfully, but these errors were encountered: