From 8b2059047d273ddea0884524ea3c5b99e3d0f59c Mon Sep 17 00:00:00 2001 From: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Date: Wed, 30 Mar 2022 20:00:57 +0200 Subject: [PATCH] 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 Co-authored-by: Pierre Sassoulas --- ChangeLog | 6 ++++++ pylint/checkers/ellipsis_checker.py | 8 +++++++- .../functional/u/unnecessary/unnecessary_ellipsis.py | 11 +++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5ae55075c4..34ab7bbcf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/pylint/checkers/ellipsis_checker.py b/pylint/checkers/ellipsis_checker.py index ac5e04095e..1c7a7bebfc 100644 --- a/pylint/checkers/ellipsis_checker.py +++ b/pylint/checkers/ellipsis_checker.py @@ -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 diff --git a/tests/functional/u/unnecessary/unnecessary_ellipsis.py b/tests/functional/u/unnecessary/unnecessary_ellipsis.py index 1a6ed777c2..baba0bbc02 100644 --- a/tests/functional/u/unnecessary/unnecessary_ellipsis.py +++ b/tests/functional/u/unnecessary/unnecessary_ellipsis.py @@ -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': (...,)}