-
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.
Handle non-Name
elts
in Expr::ListComp
- Loading branch information
1 parent
559ba63
commit be8e7b6
Showing
5 changed files
with
246 additions
and
30 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
170 changes: 170 additions & 0 deletions
170
crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF015_RUF015.py.snap
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,170 @@ | ||
--- | ||
source: crates/ruff/src/rules/ruff/mod.rs | ||
--- | ||
RUF015.py:4:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
3 | # RUF015 | ||
4 | list(x)[0] | ||
| ^^^^^^^^^^ RUF015 | ||
5 | list(x)[:1] | ||
6 | list(x)[:1:1] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
1 1 | x = range(10) | ||
2 2 | | ||
3 3 | # RUF015 | ||
4 |-list(x)[0] | ||
4 |+next(iter(x)) | ||
5 5 | list(x)[:1] | ||
6 6 | list(x)[:1:1] | ||
7 7 | list(x)[:1:2] | ||
|
||
RUF015.py:5:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
3 | # RUF015 | ||
4 | list(x)[0] | ||
5 | list(x)[:1] | ||
| ^^^^^^^^^^^ RUF015 | ||
6 | list(x)[:1:1] | ||
7 | list(x)[:1:2] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
2 2 | | ||
3 3 | # RUF015 | ||
4 4 | list(x)[0] | ||
5 |-list(x)[:1] | ||
5 |+next(iter(x)) | ||
6 6 | list(x)[:1:1] | ||
7 7 | list(x)[:1:2] | ||
8 8 | [i for i in x][0] | ||
|
||
RUF015.py:6:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
4 | list(x)[0] | ||
5 | list(x)[:1] | ||
6 | list(x)[:1:1] | ||
| ^^^^^^^^^^^^^ RUF015 | ||
7 | list(x)[:1:2] | ||
8 | [i for i in x][0] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
3 3 | # RUF015 | ||
4 4 | list(x)[0] | ||
5 5 | list(x)[:1] | ||
6 |-list(x)[:1:1] | ||
6 |+next(iter(x)) | ||
7 7 | list(x)[:1:2] | ||
8 8 | [i for i in x][0] | ||
9 9 | [i for i in x][:1] | ||
|
||
RUF015.py:7:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
5 | list(x)[:1] | ||
6 | list(x)[:1:1] | ||
7 | list(x)[:1:2] | ||
| ^^^^^^^^^^^^^ RUF015 | ||
8 | [i for i in x][0] | ||
9 | [i for i in x][:1] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
4 4 | list(x)[0] | ||
5 5 | list(x)[:1] | ||
6 6 | list(x)[:1:1] | ||
7 |-list(x)[:1:2] | ||
7 |+next(iter(x)) | ||
8 8 | [i for i in x][0] | ||
9 9 | [i for i in x][:1] | ||
10 10 | [i for i in x][:1:1] | ||
|
||
RUF015.py:8:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
6 | list(x)[:1:1] | ||
7 | list(x)[:1:2] | ||
8 | [i for i in x][0] | ||
| ^^^^^^^^^^^^^^^^^ RUF015 | ||
9 | [i for i in x][:1] | ||
10 | [i for i in x][:1:1] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
5 5 | list(x)[:1] | ||
6 6 | list(x)[:1:1] | ||
7 7 | list(x)[:1:2] | ||
8 |-[i for i in x][0] | ||
8 |+next(iter(x)) | ||
9 9 | [i for i in x][:1] | ||
10 10 | [i for i in x][:1:1] | ||
11 11 | [i for i in x][:1:2] | ||
|
||
RUF015.py:9:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
7 | list(x)[:1:2] | ||
8 | [i for i in x][0] | ||
9 | [i for i in x][:1] | ||
| ^^^^^^^^^^^^^^^^^^ RUF015 | ||
10 | [i for i in x][:1:1] | ||
11 | [i for i in x][:1:2] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
6 6 | list(x)[:1:1] | ||
7 7 | list(x)[:1:2] | ||
8 8 | [i for i in x][0] | ||
9 |-[i for i in x][:1] | ||
9 |+next(iter(x)) | ||
10 10 | [i for i in x][:1:1] | ||
11 11 | [i for i in x][:1:2] | ||
12 12 | | ||
|
||
RUF015.py:10:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
8 | [i for i in x][0] | ||
9 | [i for i in x][:1] | ||
10 | [i for i in x][:1:1] | ||
| ^^^^^^^^^^^^^^^^^^^^ RUF015 | ||
11 | [i for i in x][:1:2] | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
7 7 | list(x)[:1:2] | ||
8 8 | [i for i in x][0] | ||
9 9 | [i for i in x][:1] | ||
10 |-[i for i in x][:1:1] | ||
10 |+next(iter(x)) | ||
11 11 | [i for i in x][:1:2] | ||
12 12 | | ||
13 13 | # Fine - not indexing (solely) the first element | ||
|
||
RUF015.py:11:1: RUF015 [*] Prefer `next(iter(x))` over `list(x)[0]` or equivalent list comprehension | ||
| | ||
9 | [i for i in x][:1] | ||
10 | [i for i in x][:1:1] | ||
11 | [i for i in x][:1:2] | ||
| ^^^^^^^^^^^^^^^^^^^^ RUF015 | ||
12 | | ||
13 | # Fine - not indexing (solely) the first element | ||
| | ||
= help: Convert `list(x)[0]` or equivalent list comprehension call to `next(iter(x))` | ||
|
||
ℹ Suggested fix | ||
8 8 | [i for i in x][0] | ||
9 9 | [i for i in x][:1] | ||
10 10 | [i for i in x][:1:1] | ||
11 |-[i for i in x][:1:2] | ||
11 |+next(iter(x)) | ||
12 12 | | ||
13 13 | # Fine - not indexing (solely) the first element | ||
14 14 | list(x) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.