Skip to content

Commit 5fb17e0

Browse files
GideonBearmbyrnepr2Pierre-Sassoulas
committed
multiple-statements no longer triggers for function stubs using inlined ... (#7863)
Co-authored-by: Mark Byrne <[email protected]> Co-authored-by: Pierre Sassoulas <[email protected]> (cherry picked from commit 6b427a9)
1 parent 5a96370 commit 5fb17e0

File tree

6 files changed

+10
-15
lines changed

6 files changed

+10
-15
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``multiple-statements`` no longer triggers for function stubs using inlined ``...``.
2+
3+
Closes #7860

pylint/checkers/format.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
from astroid import nodes
2323

2424
from pylint.checkers import BaseRawFileChecker, BaseTokenChecker
25-
from pylint.checkers.utils import (
26-
is_overload_stub,
27-
is_protocol_class,
28-
node_frame_class,
29-
only_required_for_messages,
30-
)
25+
from pylint.checkers.utils import only_required_for_messages
3126
from pylint.constants import WarningScope
3227
from pylint.interfaces import HIGH
3328
from pylint.typing import MessageDefinitionTuple
@@ -567,15 +562,14 @@ def _check_multi_statement_line(self, node: nodes.NodeNG, line: int) -> None:
567562
):
568563
return
569564

570-
# Function overloads that use ``Ellipsis`` are exempted.
565+
# Functions stubs with ``Ellipsis`` as body are exempted.
571566
if (
572-
isinstance(node, nodes.Expr)
567+
isinstance(node.parent, nodes.FunctionDef)
568+
and isinstance(node, nodes.Expr)
573569
and isinstance(node.value, nodes.Const)
574570
and node.value.value is Ellipsis
575571
):
576-
frame = node.frame(future=True)
577-
if is_overload_stub(frame) or is_protocol_class(node_frame_class(frame)):
578-
return
572+
return
579573

580574
self.add_message("multiple-statements", node=node)
581575
self._visited_lines[line] = 2

tests/functional/m/multiple_statements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ class MyError(Exception): a='a'; b='b' # [multiple-statements]
2727
@overload
2828
def concat2(arg1: str) -> str: ...
2929

30-
def concat2(arg1: str) -> str: ... # [multiple-statements]
30+
def concat2(arg1: str) -> str: ...

tests/functional/m/multiple_statements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ multiple-statements:9:9:9:13::More than one statement on a single line:UNDEFINED
33
multiple-statements:13:26:13:30:MyError:More than one statement on a single line:UNDEFINED
44
multiple-statements:15:26:15:31:MyError:More than one statement on a single line:UNDEFINED
55
multiple-statements:17:26:17:31:MyError:More than one statement on a single line:UNDEFINED
6-
multiple-statements:30:31:30:34:concat2:More than one statement on a single line:UNDEFINED

tests/functional/m/multiple_statements_single_line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ class MyError(Exception): a='a'; b='b' # [multiple-statements]
2727
@overload
2828
def concat2(arg1: str) -> str: ...
2929

30-
def concat2(arg1: str) -> str: ... # [multiple-statements]
30+
def concat2(arg1: str) -> str: ...
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
multiple-statements:9:9:9:13::More than one statement on a single line:UNDEFINED
22
multiple-statements:17:26:17:31:MyError:More than one statement on a single line:UNDEFINED
3-
multiple-statements:30:31:30:34:concat2:More than one statement on a single line:UNDEFINED

0 commit comments

Comments
 (0)