Handle more functions that never return in RET503 (#2719)

This commit is contained in:
Nick Pope 2023-02-10 17:09:05 +00:00 committed by GitHub
parent cda2ff0b18
commit 9e6f7153a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 29 deletions

View file

@ -1,7 +1,10 @@
import builtins
import os
import posix
from posix import abort
import sys as std_sys
import _thread
import _winapi
import pytest
from pytest import xfail as py_xfail
@ -148,30 +151,78 @@ def prompts(self, foo):
# Functions that never return
def noreturn__exit(x):
def noreturn_exit(x):
if x > 0:
return 1
exit()
def noreturn_quit(x):
if x > 0:
return 1
quit()
def noreturn_builtins_exit(x):
if x > 0:
return 1
builtins.exit()
def noreturn_builtins_quit(x):
if x > 0:
return 1
builtins.quit()
def noreturn_os__exit(x):
if x > 0:
return 1
os._exit(0)
def noreturn_abort(x):
def noreturn_os_abort(x):
if x > 0:
return 1
os.abort()
def noreturn_abort_2():
def noreturn_posix__exit():
if x > 0:
return 1
posix._exit()
def noreturn_posix_abort():
if x > 0:
return 1
posix.abort()
def noreturn_posix_abort_2():
if x > 0:
return 1
abort()
def noreturn_exit():
def noreturn_sys_exit():
if x > 0:
return 1
std_sys.exit(0)
def noreturn__thread_exit():
if x > 0:
return 1
_thread.exit(0)
def noreturn__winapi_exitprocess():
if x > 0:
return 1
_winapi.ExitProcess(0)
def noreturn_pytest_exit():
if x > 0:
return 1
@ -191,6 +242,12 @@ def noreturn_pytest_skip():
def noreturn_pytest_xfail():
if x > 0:
return 1
pytest.xfail("oof")
def noreturn_pytest_xfail_2():
if x > 0:
return 1
py_xfail("oof")

View file

@ -168,11 +168,17 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
const NORETURN_FUNCS: &[&[&str]] = &[
// builtins
&["", "exit"],
&["", "quit"],
// stdlib
&["builtins", "exit"],
&["builtins", "quit"],
&["os", "_exit"],
&["os", "abort"],
&["posix", "_exit"],
&["posix", "abort"],
&["sys", "exit"],
&["_thread", "exit"],
&["_winapi", "ExitProcess"],
// third-party modules
&["pytest", "exit"],
&["pytest", "fail"],

View file

@ -1,120 +1,120 @@
---
source: src/rules/flake8_return/mod.rs
source: crates/ruff/src/rules/flake8_return/mod.rs
expression: diagnostics
---
- kind:
ImplicitReturn: ~
location:
row: 15
row: 18
column: 4
end_location:
row: 16
row: 19
column: 16
fix: ~
parent: ~
- kind:
ImplicitReturn: ~
location:
row: 22
row: 25
column: 8
end_location:
row: 22
row: 25
column: 15
fix:
content:
- " return None"
- ""
location:
row: 23
row: 26
column: 0
end_location:
row: 23
row: 26
column: 0
parent: ~
- kind:
ImplicitReturn: ~
location:
row: 31
row: 34
column: 4
end_location:
row: 31
row: 34
column: 11
fix:
content:
- " return None"
- ""
location:
row: 32
row: 35
column: 0
end_location:
row: 32
row: 35
column: 0
parent: ~
- kind:
ImplicitReturn: ~
location:
row: 37
row: 40
column: 8
end_location:
row: 38
row: 41
column: 20
fix: ~
parent: ~
- kind:
ImplicitReturn: ~
location:
row: 47
row: 50
column: 8
end_location:
row: 47
row: 50
column: 15
fix:
content:
- " return None"
- ""
location:
row: 48
row: 51
column: 0
end_location:
row: 48
row: 51
column: 0
parent: ~
- kind:
ImplicitReturn: ~
location:
row: 54
row: 57
column: 4
end_location:
row: 54
row: 57
column: 22
fix:
content:
- " return None"
- ""
location:
row: 55
row: 58
column: 0
end_location:
row: 55
row: 58
column: 0
parent: ~
- kind:
ImplicitReturn: ~
location:
row: 61
row: 64
column: 4
end_location:
row: 61
row: 64
column: 21
fix:
content:
- " return None"
- ""
location:
row: 62
row: 65
column: 0
end_location:
row: 62
row: 65
column: 0
parent: ~