-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-return
] Recognize functions returning Never
as non-return…
…ing (`RET503`)
- Loading branch information
Showing
6 changed files
with
162 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
crates/ruff_linter/resources/test/fixtures/flake8_return/RET503_nested_functions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from posix import abort | ||
from typing import NoReturn | ||
|
||
import typing_extensions | ||
|
||
|
||
|
||
# function return type annotation NoReturn | ||
def foo(x: int) -> int: | ||
def bar() -> NoReturn: | ||
abort() | ||
if x == 5: | ||
return 5 | ||
bar() | ||
|
||
|
||
def foo(string: str) -> str: | ||
def raises(value: str) -> NoReturn: | ||
raise RuntimeError("something went wrong") | ||
|
||
match string: | ||
case "a": | ||
return "first" | ||
case "b": | ||
return "second" | ||
case "c": | ||
return "third" | ||
case _: | ||
raises(string) | ||
|
||
|
||
def foo() -> int: | ||
def baz() -> int: | ||
return 1 | ||
|
||
|
||
def bar() -> NoReturn: | ||
a = 1 + 2 | ||
raise AssertionError("Very bad") | ||
|
||
|
||
|
||
if baz() > 3: | ||
return 1 | ||
bar() | ||
|
||
|
||
|
||
# function return type annotation typing_extensions.Never | ||
def foo(x: int) -> int: | ||
def bar() -> typing_extensions.Never: | ||
abort() | ||
if x == 5: | ||
return 5 | ||
bar() | ||
|
||
|
||
def foo(string: str) -> str: | ||
def raises(value: str) -> typing_extensions.Never: | ||
raise RuntimeError("something went wrong") | ||
|
||
match string: | ||
case "a": | ||
return "first" | ||
case "b": | ||
return "second" | ||
case "c": | ||
return "third" | ||
case _: | ||
raises(string) | ||
|
||
|
||
def foo() -> int: | ||
def baz() -> int: | ||
return 1 | ||
|
||
|
||
def bar() -> typing_extensions.Never: | ||
a = 1 + 2 | ||
raise AssertionError("Very bad") | ||
|
||
|
||
|
||
if baz() > 3: | ||
return 1 | ||
bar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters