Skip to content

Commit

Permalink
[multiple-statements] Exclude the class with Ellipsis from the check
Browse files Browse the repository at this point in the history
Closes #9398
  • Loading branch information
Pierre-Sassoulas committed Jun 5, 2024
1 parent a1951c7 commit d985462
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9398.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Classes with only an Ellipsis (``...``) in their body do not trigger 'multiple-statements'
anymore if they are inlined (in accordance with black's 2024 style).

Closes #9398
9 changes: 4 additions & 5 deletions pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,8 @@ def visit_default(self, node: nodes.NodeNG) -> None:

def _check_multi_statement_line(self, node: nodes.NodeNG, line: int) -> None:
"""Check for lines containing multiple statements."""
# Do not warn about multiple nested context managers
# in with statements.
if isinstance(node, nodes.With):
# Do not warn about multiple nested context managers in with statements.
return
if (
isinstance(node.parent, nodes.If)
Expand All @@ -539,10 +538,10 @@ def _check_multi_statement_line(self, node: nodes.NodeNG, line: int) -> None:
):
return

# Functions stubs with ``Ellipsis`` as body are exempted.
# Functions stubs and class with ``Ellipsis`` as body are exempted.
if (
isinstance(node.parent, nodes.FunctionDef)
and isinstance(node, nodes.Expr)
isinstance(node, nodes.Expr)
and isinstance(node.parent, (nodes.FunctionDef, nodes.ClassDef))
and isinstance(node.value, nodes.Const)
and node.value.value is Ellipsis
):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/m/multiple_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# (only for classes, not for the examples above)
class MyException(Exception): print("Golfing sure is nice") # [multiple-statements]
class MyError(Exception): pass # [multiple-statements]
class DebugTrueDetected(Exception): ... # [multiple-statements]
class DebugTrueDetected(Exception): ...

class MyError(Exception): a='a' # [multiple-statements]

Expand Down
1 change: 0 additions & 1 deletion tests/functional/m/multiple_statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ multiple-statements:15:9:15:13::More than one statement on a single line:HIGH
multiple-statements:19:9:19:12::More than one statement on a single line:HIGH
multiple-statements:26:30:26:59:MyException:More than one statement on a single line:HIGH
multiple-statements:27:26:27:30:MyError:More than one statement on a single line:HIGH
multiple-statements:28:36:28:39:DebugTrueDetected:More than one statement on a single line:HIGH
multiple-statements:30:26:30:31:MyError:More than one statement on a single line:HIGH
multiple-statements:32:26:32:31:MyError:More than one statement on a single line:HIGH

0 comments on commit d985462

Please sign in to comment.