From b967fd9baa78ea19015b3f1fdada710e35435c38 Mon Sep 17 00:00:00 2001 From: Gideon <87426140+GideonBear@users.noreply.github.com> Date: Tue, 29 Nov 2022 11:39:48 +0100 Subject: [PATCH 1/2] ``multiple-statements`` no longer triggers for function stubs using inlined ``...`` (#7863) Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Co-authored-by: Pierre Sassoulas (cherry picked from commit 6b427a9189c86143bc361c56393e028ad3e5c3e1) --- doc/whatsnew/fragments/7860.false_positive | 3 +++ pylint/checkers/format.py | 16 +++++----------- tests/functional/m/multiple_statements.py | 2 +- tests/functional/m/multiple_statements.txt | 1 - .../m/multiple_statements_single_line.py | 2 +- .../m/multiple_statements_single_line.txt | 1 - 6 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 doc/whatsnew/fragments/7860.false_positive diff --git a/doc/whatsnew/fragments/7860.false_positive b/doc/whatsnew/fragments/7860.false_positive new file mode 100644 index 0000000000..c76425c54b --- /dev/null +++ b/doc/whatsnew/fragments/7860.false_positive @@ -0,0 +1,3 @@ +``multiple-statements`` no longer triggers for function stubs using inlined ``...``. + +Closes #7860 diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index 5d9a854b92..2a42ef4465 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -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 @@ -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 diff --git a/tests/functional/m/multiple_statements.py b/tests/functional/m/multiple_statements.py index 5b55eac424..c3252f797c 100644 --- a/tests/functional/m/multiple_statements.py +++ b/tests/functional/m/multiple_statements.py @@ -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: ... diff --git a/tests/functional/m/multiple_statements.txt b/tests/functional/m/multiple_statements.txt index 34d80508ed..661314268d 100644 --- a/tests/functional/m/multiple_statements.txt +++ b/tests/functional/m/multiple_statements.txt @@ -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 diff --git a/tests/functional/m/multiple_statements_single_line.py b/tests/functional/m/multiple_statements_single_line.py index 4a77d992ea..93a470702c 100644 --- a/tests/functional/m/multiple_statements_single_line.py +++ b/tests/functional/m/multiple_statements_single_line.py @@ -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: ... diff --git a/tests/functional/m/multiple_statements_single_line.txt b/tests/functional/m/multiple_statements_single_line.txt index a28fc96c4d..cac2f7eb2e 100644 --- a/tests/functional/m/multiple_statements_single_line.txt +++ b/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 From e6755f66fb78566ef2701f241f6b4b7f903c287f Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 4 Dec 2022 16:24:53 +0100 Subject: [PATCH 2/2] [github actions] Reinstate tests and check on maintenance branch --- .github/workflows/checks.yaml | 5 ++++- .github/workflows/tests.yaml | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 4392e7a5cf..d49a4711ac 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -5,7 +5,10 @@ on: branches: - main - "maintenance/**" - pull_request: ~ + pull_request: + branches: + - main + - "maintenance/**" env: CACHE_VERSION: 1 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9d741197c6..6652130b9b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -7,7 +7,10 @@ on: - "maintenance/**" paths-ignore: - doc/data/messages/** - pull_request: ~ + pull_request: + branches: + - main + - "maintenance/**" env: CACHE_VERSION: 1