Skip to content

Commit 8912838

Browse files
Pierre-SassoulasDanielNoord
authored andcommitted
[consider-using-sys-exit] Better rationale and added confidence
1 parent 160add5 commit 8912838

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

doc/user_guide/checkers/features.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,9 @@ Refactoring checker Messages
764764
:consider-using-min-builtin (R1730): *Consider using '%s' instead of unnecessary if block*
765765
Using the min builtin instead of a conditional improves readability and
766766
conciseness.
767+
:consider-using-sys-exit (R1722): *Consider using 'sys.exit' instead*
768+
Contrary to 'exit()' or 'quit()', 'sys.exit' does not rely on the site module
769+
being available (as the 'sys' module is always available).
767770
:consider-using-with (R1732): *Consider using 'with' for resource-allocating operations*
768771
Emitted if a resource-allocating assignment or call may be replaced by a
769772
'with' block. By using 'with' the release of the allocated resources is
@@ -793,8 +796,6 @@ Refactoring checker Messages
793796
:consider-using-join (R1713): *Consider using str.join(sequence) for concatenating strings from an iterable*
794797
Using str.join(sequence) is faster, uses less memory and increases
795798
readability compared to for-loop iteration.
796-
:consider-using-sys-exit (R1722): *Consider using sys.exit()*
797-
Instead of using exit() or quit(), consider using the sys.exit().
798799
:consider-using-ternary (R1706): *Consider using ternary (%s)*
799800
Used when one of known pre-python 2.5 ternary syntax is used.
800801
:consider-swap-variables (R1712): *Consider using tuple unpacking for swapping variables*

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,10 @@ class RefactoringChecker(checkers.BaseTokenChecker):
405405
"It is faster and simpler.",
406406
),
407407
"R1722": (
408-
"Consider using sys.exit()",
408+
"Consider using 'sys.exit' instead",
409409
"consider-using-sys-exit",
410-
"Instead of using exit() or quit(), consider using the sys.exit().",
410+
"Contrary to 'exit()' or 'quit()', 'sys.exit' does not rely on the "
411+
"site module being available (as the 'sys' module is always available).",
411412
),
412413
"R1723": (
413414
'Unnecessary "%s" after "break", %s',
@@ -1121,7 +1122,7 @@ def _check_quit_exit_call(self, node: nodes.Call) -> None:
11211122
node.root()
11221123
):
11231124
return
1124-
self.add_message("consider-using-sys-exit", node=node)
1125+
self.add_message("consider-using-sys-exit", node=node, confidence=HIGH)
11251126

11261127
def _check_super_with_arguments(self, node: nodes.Call) -> None:
11271128
if not isinstance(node.func, nodes.Name) or node.func.name != "super":
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
consider-using-sys-exit:5:4:5:10:foo:Consider using sys.exit():UNDEFINED
2-
consider-using-sys-exit:8:4:8:10:foo_1:Consider using sys.exit():UNDEFINED
3-
consider-using-sys-exit:14:0:14:6::Consider using sys.exit():UNDEFINED
1+
consider-using-sys-exit:5:4:5:10:foo:Consider using 'sys.exit' instead:HIGH
2+
consider-using-sys-exit:8:4:8:10:foo_1:Consider using 'sys.exit' instead:HIGH
3+
consider-using-sys-exit:14:0:14:6::Consider using 'sys.exit' instead:HIGH

0 commit comments

Comments
 (0)