Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnecessary-ellipsis false positive: allow ellipsis as default argument #6007

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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."