Skip to content

Commit

Permalink
multiple-statements no longer triggers for function stubs using i…
Browse files Browse the repository at this point in the history
…nlined ``...`` (#7863)

Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
(cherry picked from commit 6b427a9)
  • Loading branch information
GideonBear authored and Pierre-Sassoulas committed Dec 4, 2022
1 parent 5a96370 commit 5fb17e0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7860.false_positive
@@ -0,0 +1,3 @@
``multiple-statements`` no longer triggers for function stubs using inlined ``...``.

Closes #7860
16 changes: 5 additions & 11 deletions pylint/checkers/format.py
Expand Up @@ -22,12 +22,7 @@
from astroid import nodes

from pylint.checkers import BaseRawFileChecker, BaseTokenChecker
from pylint.checkers.utils import (
is_overload_stub,
is_protocol_class,
node_frame_class,
only_required_for_messages,
)
from pylint.checkers.utils import only_required_for_messages
from pylint.constants import WarningScope
from pylint.interfaces import HIGH
from pylint.typing import MessageDefinitionTuple
Expand Down Expand Up @@ -567,15 +562,14 @@ def _check_multi_statement_line(self, node: nodes.NodeNG, line: int) -> None:
):
return

# Function overloads that use ``Ellipsis`` are exempted.
# Functions stubs with ``Ellipsis`` as body are exempted.
if (
isinstance(node, nodes.Expr)
isinstance(node.parent, nodes.FunctionDef)
and isinstance(node, nodes.Expr)
and isinstance(node.value, nodes.Const)
and node.value.value is Ellipsis
):
frame = node.frame(future=True)
if is_overload_stub(frame) or is_protocol_class(node_frame_class(frame)):
return
return

self.add_message("multiple-statements", node=node)
self._visited_lines[line] = 2
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/m/multiple_statements.py
Expand Up @@ -27,4 +27,4 @@ class MyError(Exception): a='a'; b='b' # [multiple-statements]
@overload
def concat2(arg1: str) -> str: ...

def concat2(arg1: str) -> str: ... # [multiple-statements]
def concat2(arg1: str) -> str: ...
1 change: 0 additions & 1 deletion tests/functional/m/multiple_statements.txt
Expand Up @@ -3,4 +3,3 @@ multiple-statements:9:9:9:13::More than one statement on a single line:UNDEFINED
multiple-statements:13:26:13:30:MyError:More than one statement on a single line:UNDEFINED
multiple-statements:15:26:15:31:MyError:More than one statement on a single line:UNDEFINED
multiple-statements:17:26:17:31:MyError:More than one statement on a single line:UNDEFINED
multiple-statements:30:31:30:34:concat2:More than one statement on a single line:UNDEFINED
2 changes: 1 addition & 1 deletion tests/functional/m/multiple_statements_single_line.py
Expand Up @@ -27,4 +27,4 @@ class MyError(Exception): a='a'; b='b' # [multiple-statements]
@overload
def concat2(arg1: str) -> str: ...

def concat2(arg1: str) -> str: ... # [multiple-statements]
def concat2(arg1: str) -> str: ...
1 change: 0 additions & 1 deletion tests/functional/m/multiple_statements_single_line.txt
@@ -1,3 +1,2 @@
multiple-statements:9:9:9:13::More than one statement on a single line:UNDEFINED
multiple-statements:17:26:17:31:MyError:More than one statement on a single line:UNDEFINED
multiple-statements:30:31:30:34:concat2:More than one statement on a single line:UNDEFINED

0 comments on commit 5fb17e0

Please sign in to comment.