Skip to content

Commit 57a4d13

Browse files
mbyrnepr2DanielNoord
authored andcommitted
Narrow the scope of the unnecessary-ellipsis checker (#6081)
* Narrow the scope of the ``unnecessary-ellipsis`` checker to functions & classes which contain both a docstring and an ellipsis. * Emit the warning when the body contains an ellipsis expression and at least one other item. Co-authored-by: Daniël van Noord <[email protected]>
1 parent 14ae9e8 commit 57a4d13

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ What's New in Pylint 2.13.5?
2020
============================
2121
Release date: TBA
2222

23+
* Narrow the scope of the ``unnecessary-ellipsis`` checker to:
24+
* functions & classes which contain both a docstring and an ellipsis.
25+
* A body which contains an ellipsis ``nodes.Expr`` node & at least one other statement.
26+
2327

2428

2529
What's New in Pylint 2.13.4?

pylint/checkers/ellipsis_checker.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,13 @@ def visit_const(self, node: nodes.Const) -> None:
4141
"""
4242
if (
4343
node.pytype() == "builtins.Ellipsis"
44-
and not isinstance(
45-
node.parent,
46-
(
47-
nodes.AnnAssign,
48-
nodes.Arguments,
49-
nodes.Assign,
50-
nodes.BaseContainer,
51-
nodes.Call,
52-
nodes.Lambda,
53-
),
54-
)
44+
and isinstance(node.parent, nodes.Expr)
5545
and (
56-
len(node.parent.parent.child_sequence(node.parent)) > 1
57-
or (
46+
(
5847
isinstance(node.parent.parent, (nodes.ClassDef, nodes.FunctionDef))
5948
and node.parent.parent.doc_node
6049
)
50+
or len(node.parent.parent.body) > 1
6151
)
6252
):
6353
self.add_message("unnecessary-ellipsis", node=node)

tests/functional/u/unnecessary/unnecessary_ellipsis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
A = 2
1010
except ValueError:
1111
A = 24
12-
... # [unnecessary-ellipsis]
12+
... # [unnecessary-ellipsis]
1313

1414
def ellipsis_and_subsequent_statement():
15-
... # [unnecessary-ellipsis]
15+
... # [unnecessary-ellipsis]
1616
return 0
1717

1818
# The parent of ellipsis is an assignment

0 commit comments

Comments
 (0)