-
-
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
Changes from all commits
c7a3fc4
f1df60a
039de86
9570a39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
# 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. And what will happen for just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No error for the first, error for the second |
||
if arg: | ||
return "false" | ||
|
||
def unsound_implicit_return(arg) -> str: # E: Incompatible return value type (implicitly returns "None", expected "str") | ||
if arg: | ||
return "false" | ||
|
||
def implicit_return_gen(arg) -> typing.Generator[int, None, typing.Optional[str]]: | ||
yield 1 | ||
|
||
def unsound_implicit_return_gen(arg) -> typing.Generator[int, None, str]: # E: Incompatible return value type (implicitly returns "None", expected "str") | ||
yield 1 | ||
[builtins fixtures/dict.pyi] | ||
|
||
[case testNoWarnNoReturnNoStrictOptional] | ||
# flags: --no-warn-no-return --no-strict-optional | ||
import typing | ||
|
||
def implicit_optional_return(arg) -> typing.Optional[str]: | ||
if arg: | ||
return "false" | ||
|
||
def unsound_implicit_return(arg) -> str: | ||
if arg: | ||
return "false" | ||
|
||
def implicit_return_gen(arg) -> typing.Generator[int, None, typing.Optional[str]]: | ||
yield 1 | ||
|
||
def unsound_implicit_return_gen(arg) -> typing.Generator[int, None, str]: | ||
yield 1 | ||
[builtins fixtures/dict.pyi] | ||
|
||
[case testNoReturnImportFromTyping] | ||
from typing import NoReturn | ||
|
||
|
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
...
andpass
?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)