summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGideon <87426140+GideonBear@users.noreply.github.com>2022-11-29 11:39:48 +0100
committerGitHub <noreply@github.com>2022-11-29 11:39:48 +0100
commit6b427a9189c86143bc361c56393e028ad3e5c3e1 (patch)
treee496512a3371db32857456b66c3a00aa1c9b44c5
parent62420bdd24e224f43ab8aea4b300bc7aab7bc7ab (diff)
downloadpylint-git-6b427a9189c86143bc361c56393e028ad3e5c3e1.tar.gz
``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 <pierre.sassoulas@gmail.com>
-rw-r--r--doc/whatsnew/fragments/7860.false_positive3
-rw-r--r--pylint/checkers/format.py16
-rw-r--r--tests/functional/m/multiple_statements.py2
-rw-r--r--tests/functional/m/multiple_statements.txt1
-rw-r--r--tests/functional/m/multiple_statements_single_line.py2
-rw-r--r--tests/functional/m/multiple_statements_single_line.txt1
6 files changed, 10 insertions, 15 deletions
diff --git a/doc/whatsnew/fragments/7860.false_positive b/doc/whatsnew/fragments/7860.false_positive
new file mode 100644
index 000000000..c76425c54
--- /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 cde34b5d7..001330b2b 100644
--- a/pylint/checkers/format.py
+++ b/pylint/checkers/format.py
@@ -22,12 +22,7 @@ from typing import TYPE_CHECKING
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
@@ -563,15 +558,14 @@ class FormatChecker(BaseTokenChecker, BaseRawFileChecker):
):
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 5b55eac42..c3252f797 100644
--- a/tests/functional/m/multiple_statements.py
+++ b/tests/functional/m/multiple_statements.py
@@ -27,4 +27,4 @@ finally:
@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 34d80508e..661314268 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 4a77d992e..93a470702 100644
--- a/tests/functional/m/multiple_statements_single_line.py
+++ b/tests/functional/m/multiple_statements_single_line.py
@@ -27,4 +27,4 @@ finally:
@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 a28fc96c4..cac2f7eb2 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