Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash for unneccessary-ellipsis checker #6038

5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ 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?
============================
Expand Down
8 changes: 7 additions & 1 deletion pylint/checkers/ellipsis_checker.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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': (...,)}