-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Check implicit None return is valid when using --no-warn-no-return
#13219
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
Check implicit None return is valid when using --no-warn-no-return
#13219
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Awesome! |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add some docs please? Because it is not clear to me how this works. I assume it is an opposite of --warn-no-return
, but not like a "full" opposite, but a partial one for an implicit None
return? Kinda?
Anyway, it looks like a lot of people are happy about it 🙂
# flags: --no-warn-no-return --strict-optional | ||
import typing | ||
|
||
def implicit_optional_return(arg) -> typing.Optional[str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen for a case like:
def implicit_optional_no_return() -> Optional[int]:
print(1) # or any other non-primitive body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what will happen for just -> int
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No error for the first, error for the second Incompatible return value type (implicitly returns "None", expected "int")
. Same as the existing test cases, since the if
statement has no impact on reachability.
@@ -410,6 +410,44 @@ async def h() -> NoReturn: # E: Implicit return in function which does not retu | |||
[builtins fixtures/dict.pyi] | |||
[typing fixtures/typing-async.pyi] | |||
|
|||
[case testNoWarnNoReturn] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need test cases for ...
and pass
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no change of behaviour here, so covered by existing tests. (Also note that every test would complain about errors in stubs if the trivial body logic breaks — I know because I broke this locally initially)
No, it continues to be a full opposite of I suspect this got overlooked because the old behaviour was written back when |
The new error generated isn't really anything to do with explicit returns or implicit returns, it's just type checking the logic of the function per Python semantics. To take your example from #13203 (comment)
Previously, when using |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Fixes #7511