Skip to content

Commit

Permalink
unnecessary-ellipsis false positive: allow ellipsis as default argu…
Browse files Browse the repository at this point in the history
…ment (#6007)
  • Loading branch information
jpy-git authored and Pierre-Sassoulas committed Mar 29, 2022
1 parent 19e6531 commit c733530
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pylint/checkers/ellipsis_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 5 additions & 1 deletion tests/functional/u/unnecessary/unnecessary_ellipsis.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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."

0 comments on commit c733530

Please sign in to comment.