-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New checker - Detect use of unnecessary ellipsis
Closes #5460
- Loading branch information
Showing
8 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
class Class: | ||
attr: int | ||
... | ||
|
||
|
||
# `bar` definitely does not exist here, but in a complex scenario, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Emit a warning when the ellipsis constant is used and can be avoided""" | ||
|
||
# pylint: disable=missing-docstring, too-few-public-methods | ||
|
||
try: | ||
A = 2 | ||
except ValueError: | ||
A = 24 | ||
... # [unnecessary-ellipsis] | ||
|
||
B = ... | ||
C = [..., 1, 2, 3] | ||
|
||
def docstring_only(): | ||
'''In Python, stubbed functions often have a body that contains just a | ||
single `...` constant, indicating that the function doesn't do | ||
anything. However, a stubbed function can also have just a | ||
docstring, and function with a docstring and no body also does | ||
nothing. | ||
''' | ||
|
||
|
||
# This function has no docstring, so it needs a `...` constant. | ||
def ellipsis_only(): | ||
... | ||
|
||
|
||
def docstring_and_ellipsis(): | ||
'''This function doesn't do anything, but it has a docstring, so its | ||
`...` constant is useless clutter. | ||
NEW CHECK: unnecessary-ellipsis | ||
This would check for stubs with both docstrings and `...` | ||
constants, suggesting the removal of the useless `...` | ||
constants | ||
''' | ||
... # [unnecessary-ellipsis] | ||
|
||
|
||
class DocstringOnly: | ||
'''The same goes for class stubs: docstring, or `...`, but not both. | ||
''' | ||
|
||
|
||
# No problem | ||
class EllipsisOnly: | ||
... | ||
|
||
|
||
class DocstringAndEllipsis: | ||
'''Whoops! Mark this one as bad too. | ||
''' | ||
... # [unnecessary-ellipsis] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
unnecessary-ellipsis:9:4:None:None::Unnecessary ellipsis constant:UNDEFINED | ||
unnecessary-ellipsis:38:4:None:None::Unnecessary ellipsis constant:UNDEFINED | ||
unnecessary-ellipsis:54:4:None:None::Unnecessary ellipsis constant:UNDEFINED |