Skip to content

Commit d12c770

Browse files
mbyrnepr2Mark ByrnePierre-Sassoulas
authored
Fix crash for unneccessary-ellipsis checker (#6038)
When an ellipsis is used inside of a list or inside a container Closes #6037 Co-authored-by: Mark Byrne <[email protected]> Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 29f1919 commit d12c770

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ Release date: TBA
4545

4646
Closes #6028
4747

48+
* Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a container.
49+
50+
Closes #6037
51+
Closes #6048
52+
4853

4954
What's New in Pylint 2.13.3?
5055
============================

pylint/checkers/ellipsis_checker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ def visit_const(self, node: nodes.Const) -> None:
4343
node.pytype() == "builtins.Ellipsis"
4444
and not isinstance(
4545
node.parent,
46-
(nodes.Assign, nodes.AnnAssign, nodes.Call, nodes.Arguments),
46+
(
47+
nodes.AnnAssign,
48+
nodes.Arguments,
49+
nodes.Assign,
50+
nodes.BaseContainer,
51+
nodes.Call,
52+
),
4753
)
4854
and (
4955
len(node.parent.parent.child_sequence(node.parent)) > 1

tests/functional/u/unnecessary/unnecessary_ellipsis.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,14 @@ def __getitem__(self, index: Union[int, slice]) -> Union[int, List[int]]:
101101
# Ellipsis is allowed as a default argument
102102
def func_with_ellipsis_default_arg(a = ...) -> None:
103103
"Some docstring."
104+
105+
106+
# Ignore if the ellipsis is inside a container:
107+
my_list = [...]
108+
my_tuple = (...,)
109+
my_set = {...}
110+
111+
# Ellipsis inside a container which is a value in a dictionary
112+
mydict1 = {'x': [...]}
113+
mydict2 = {'x': {...}}
114+
mydict3 = {'x': (...,)}

0 commit comments

Comments
 (0)