Check implicit None return is valid when using --no-warn-no-return#13219
Check implicit None return is valid when using --no-warn-no-return#13219hauntsaninja merged 4 commits intopython:masterfrom
--no-warn-no-return#13219Conversation
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.
sobolevn
left a comment
There was a problem hiding this comment.
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.
What will happen for a case like:
def implicit_optional_no_return() -> Optional[int]:
print(1) # or any other non-primitive bodyThere was a problem hiding this comment.
And what will happen for just -> int?
There was a problem hiding this comment.
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.
| [builtins fixtures/dict.pyi] | ||
| [typing fixtures/typing-async.pyi] | ||
|
|
||
| [case testNoWarnNoReturn] |
There was a problem hiding this comment.
Do we need test cases for ... and pass?
There was a problem hiding this comment.
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