From c73353064f934ae49472eb6138e1f8071b6b733e Mon Sep 17 00:00:00 2001 From: Joe Young <80432516+jpy-git@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:27:32 +0100 Subject: [PATCH] `unnecessary-ellipsis` false positive: allow ellipsis as default argument (#6007) --- ChangeLog | 4 ++++ doc/whatsnew/2.13.rst | 4 ++++ pylint/checkers/ellipsis_checker.py | 5 ++++- tests/functional/u/unnecessary/unnecessary_ellipsis.py | 6 +++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22fe55cae5..ef8c38843f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,10 @@ What's New in Pylint 2.13.3? ============================ Release date: TBA +* Fix false positive for ``unnecessary-ellipsis`` when using an ellipsis as a default argument. + + Closes #5973 + * Fix crash involving unbalanced tuple unpacking. Closes #5998 diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index 2d425d7a4a..b2c40e87e0 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -128,6 +128,10 @@ Extensions Other Changes ============= +* Fix false positive for ``unnecessary-ellipsis`` when using an ellipsis as a default argument. + + Closes #5973 + * Add missing dunder methods to ``unexpected-special-method-signature`` check. * No longer emit ``no-member`` in for loops that reference ``self`` if the binary operation that diff --git a/pylint/checkers/ellipsis_checker.py b/pylint/checkers/ellipsis_checker.py index 2d904a28d2..ac5e04095e 100644 --- a/pylint/checkers/ellipsis_checker.py +++ b/pylint/checkers/ellipsis_checker.py @@ -41,7 +41,10 @@ def visit_const(self, node: nodes.Const) -> None: """ if ( node.pytype() == "builtins.Ellipsis" - and not isinstance(node.parent, (nodes.Assign, nodes.AnnAssign, nodes.Call)) + and not isinstance( + node.parent, + (nodes.Assign, nodes.AnnAssign, nodes.Call, nodes.Arguments), + ) and ( len(node.parent.parent.child_sequence(node.parent)) > 1 or ( diff --git a/tests/functional/u/unnecessary/unnecessary_ellipsis.py b/tests/functional/u/unnecessary/unnecessary_ellipsis.py index b5a61e3493..1a6ed777c2 100644 --- a/tests/functional/u/unnecessary/unnecessary_ellipsis.py +++ b/tests/functional/u/unnecessary/unnecessary_ellipsis.py @@ -1,6 +1,6 @@ """Emit a warning when the ellipsis constant is used and can be avoided""" -# pylint: disable=missing-docstring, too-few-public-methods +# pylint: disable=missing-docstring, too-few-public-methods, invalid-name, unused-argument from typing import List, overload, Union @@ -97,3 +97,7 @@ def __getitem__(self, index: Union[int, slice]) -> Union[int, List[int]]: ... else: raise TypeError(...) + +# Ellipsis is allowed as a default argument +def func_with_ellipsis_default_arg(a = ...) -> None: + "Some docstring."