From 34683447b202aa58c250508bafe491e18f90ed3b Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Tue, 29 Mar 2022 20:14:28 +0200 Subject: [PATCH] Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a list. Closes #6037 --- ChangeLog | 4 ++++ pylint/checkers/ellipsis_checker.py | 2 +- tests/functional/u/unnecessary/unnecessary_ellipsis.py | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9214b58b17..0271f1d18d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,10 @@ Release date: TBA * Fix bug where specifically enabling just ``await-outside-async`` was not possible. +* Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a list. + + Closes #6037 + .. Insert your changelog randomly, it will reduce merge conflicts (Ie. not necessarily at the end) diff --git a/pylint/checkers/ellipsis_checker.py b/pylint/checkers/ellipsis_checker.py index ac5e04095e..767dfdc29c 100644 --- a/pylint/checkers/ellipsis_checker.py +++ b/pylint/checkers/ellipsis_checker.py @@ -43,7 +43,7 @@ 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.Assign, nodes.AnnAssign, nodes.Call, nodes.Arguments, nodes.List), ) and ( len(node.parent.parent.child_sequence(node.parent)) > 1 diff --git a/tests/functional/u/unnecessary/unnecessary_ellipsis.py b/tests/functional/u/unnecessary/unnecessary_ellipsis.py index 1a6ed777c2..4fa5b46ef7 100644 --- a/tests/functional/u/unnecessary/unnecessary_ellipsis.py +++ b/tests/functional/u/unnecessary/unnecessary_ellipsis.py @@ -101,3 +101,8 @@ 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 list +x = [...] +y = {'a': [...]}