-
-
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.
Add new checker (unnecessary-comprehension) (close #2905)
- Loading branch information
1 parent
f6df515
commit 18d9e99
Showing
18 changed files
with
111 additions
and
13 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
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
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
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,35 @@ | ||
# pylint: disable=undefined-variable, pointless-statement, missing-docstring, line-too-long, bad-whitespace | ||
# For name-reference see https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries | ||
|
||
# List comprehensions | ||
[x for x in iterable] # [unnecessary-comprehension] | ||
[y for x in iterable] # expression != target_list | ||
[x for x,y,z in iterable] # expression != target_list | ||
[(x,y,z) for x,y,z in iterable] # [unnecessary-comprehension] | ||
[(x,y,z) for (x,y,z) in iterable] # [unnecessary-comprehension] | ||
[x for x, *y in iterable] # expression != target_list | ||
[x for x in iterable if condition] # exclude comp_if | ||
[y for x in iterable for y in x] # exclude nested comprehensions | ||
[2 * x for x in iterable] # exclude useful comprehensions | ||
|
||
# Set comprehensions | ||
{x for x in iterable} # [unnecessary-comprehension] | ||
{y for x in iterable} # expression != target_list | ||
{x for x,y,z in iterable} # expression != target_list | ||
{(x,y,z) for x,y,z in iterable} # [unnecessary-comprehension] | ||
{(x,y,z) for (x, y, z) in iterable} # [unnecessary-comprehension] | ||
{(x,y,z) for x in iterable} # expression != target_list | ||
{(x,y,(a,b,c)) for x in iterable} # expression != target_list | ||
{x for x, *y in iterable} # expression != target_list | ||
{x for x in iterable if condition} # exclude comp_if | ||
{y for x in iterable for y in x} # exclude nested comprehensions | ||
|
||
# Dictionary comprehensions | ||
{x: y for x, y in iterable} # [unnecessary-comprehension] | ||
{y: x for x, y in iterable} # key value wrong order | ||
{x: y for (x, y) in iterable} # [unnecessary-comprehension] | ||
{x: y for x,y,z in iterable} # expression != target_list | ||
{x: y for x, y in iterable if condition} # exclude comp_if | ||
{y: z for x in iterable for y, z in x} # exclude nested comprehensions | ||
{x: 1 for x in iterable} # expression != target_list | ||
{2 * x: 3 + x for x in iterable} # exclude useful comprehensions |
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,8 @@ | ||
unnecessary-comprehension:5::Unnecessary use of a comprehension | ||
unnecessary-comprehension:8::Unnecessary use of a comprehension | ||
unnecessary-comprehension:9::Unnecessary use of a comprehension | ||
unnecessary-comprehension:16::Unnecessary use of a comprehension | ||
unnecessary-comprehension:19::Unnecessary use of a comprehension | ||
unnecessary-comprehension:20::Unnecessary use of a comprehension | ||
unnecessary-comprehension:28::Unnecessary use of a comprehension | ||
unnecessary-comprehension:30::Unnecessary use of a comprehension |
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