Skip to content

Commit

Permalink
Fix crash for unneccessary-ellipsis checker (#6038)
Browse files Browse the repository at this point in the history
When an ellipsis is used inside of a list or inside a container

Closes #6037

Co-authored-by: Mark Byrne <mark.byrne@rabobank.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
3 people committed Mar 31, 2022
1 parent 4966c5b commit 8b20590
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog
Expand Up @@ -24,6 +24,12 @@ Release date: TBA

Closes #6028

* Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a container.

Closes #6037
Closes #6048


What's New in Pylint 2.13.3?
============================
Release date: 2022-03-29
Expand Down
8 changes: 7 additions & 1 deletion pylint/checkers/ellipsis_checker.py
Expand Up @@ -43,7 +43,13 @@ def visit_const(self, node: nodes.Const) -> None:
node.pytype() == "builtins.Ellipsis"
and not isinstance(
node.parent,
(nodes.Assign, nodes.AnnAssign, nodes.Call, nodes.Arguments),
(
nodes.AnnAssign,
nodes.Arguments,
nodes.Assign,
nodes.BaseContainer,
nodes.Call,
),
)
and (
len(node.parent.parent.child_sequence(node.parent)) > 1
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/u/unnecessary/unnecessary_ellipsis.py
Expand Up @@ -101,3 +101,14 @@ def __getitem__(self, index: Union[int, slice]) -> Union[int, List[int]]:
# Ellipsis is allowed as a default argument
def func_with_ellipsis_default_arg(a = ...) -> None:
"Some docstring."


# Ignore if the ellipsis is inside a container:
my_list = [...]
my_tuple = (...,)
my_set = {...}

# Ellipsis inside a container which is a value in a dictionary
mydict1 = {'x': [...]}
mydict2 = {'x': {...}}
mydict3 = {'x': (...,)}

0 comments on commit 8b20590

Please sign in to comment.