-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
--strict-optional Doesn't consider cases missing return #2366
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
Relies on what behavior? |
@rwbarton updated my issue...code that relies on no return statement returning |
In the meantime you can just pass both flags right? |
OK. The way
|
Always, or implied by |
@gvanrossum Totally, but it would be a nice user experience to have them work in tandem since your types aren't really strict about optionals unless we've also asserted that all code paths return values. I agree with @rwbarton that we should iron out the kinks first though 😄 As a side note, it seems like |
Oops, I forgot how It'd be easy to make it more lenient under strict optional checking; when it was implemented strict optional checking didn't really work well yet (and even mypy itself is not yet using it). |
I don't think we should make it more lenient, though -- falling off the end of the function in those cases is still potentially an error, and it seems reasonable it me to make people be explicit. (Just like we don't allow you to write I'd like to see |
Both |
Type checks cleanly with --strict-optional but will return
None
in cases wherea
is False. This function should have to have a type signature of(bool) -> Optional[str]
.I recently came across the
--warn-no-return
flag in #1748 . Is the intention is to force all code paths in functions to hit a return statement? I know that'd be more in line with PEP 8, but unfortunately I've got tons of code that relies on the absence of a return statement implyingreturn None
that I'd like to typecheck.If this isn't a bug, I would suggest we change this to "--strict-optional should imply --warn-no-return".
The text was updated successfully, but these errors were encountered: