From 5ea03af1268ae4776e8ddd9dc55e14f465710288 Mon Sep 17 00:00:00 2001 From: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Date: Wed, 30 Mar 2022 22:20:36 +0200 Subject: [PATCH] Fix false positive for the ``unnecessary-ellipsis`` checker (#6039) When an ellipsis is used in a lambda expression. Closes #6036 Co-authored-by: Mark Byrne Co-authored-by: Pierre Sassoulas --- ChangeLog | 3 ++- pylint/checkers/ellipsis_checker.py | 1 + tests/functional/u/unnecessary/unnecessary_ellipsis.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34ab7bbcf4..85b489f4d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,8 +24,9 @@ Release date: TBA Closes #6028 -* Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a container. +* Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a container or a lambda expression. + Closes #6036 Closes #6037 Closes #6048 diff --git a/pylint/checkers/ellipsis_checker.py b/pylint/checkers/ellipsis_checker.py index 1c7a7bebfc..48d43d3b58 100644 --- a/pylint/checkers/ellipsis_checker.py +++ b/pylint/checkers/ellipsis_checker.py @@ -49,6 +49,7 @@ def visit_const(self, node: nodes.Const) -> None: nodes.Assign, nodes.BaseContainer, nodes.Call, + nodes.Lambda, ), ) and ( diff --git a/tests/functional/u/unnecessary/unnecessary_ellipsis.py b/tests/functional/u/unnecessary/unnecessary_ellipsis.py index baba0bbc02..3e967b6cd5 100644 --- a/tests/functional/u/unnecessary/unnecessary_ellipsis.py +++ b/tests/functional/u/unnecessary/unnecessary_ellipsis.py @@ -102,7 +102,6 @@ def __getitem__(self, index: Union[int, slice]) -> Union[int, List[int]]: def func_with_ellipsis_default_arg(a = ...) -> None: "Some docstring." - # Ignore if the ellipsis is inside a container: my_list = [...] my_tuple = (...,) @@ -112,3 +111,6 @@ def func_with_ellipsis_default_arg(a = ...) -> None: mydict1 = {'x': [...]} mydict2 = {'x': {...}} mydict3 = {'x': (...,)} + +# Ignore if the ellipsis is used with a lambda expression +print("x", lambda: ...)