Skip to content

Commit

Permalink
[pyflakes] Stabilize detection of is comparisons to lists, etc. (`F…
Browse files Browse the repository at this point in the history
…632`) (#12049)

## Summary

See: #8607. Rare but
uncontroversial.
  • Loading branch information
charliermarsh authored and MichaReiser committed Jun 27, 2024
1 parent 82f09ce commit d0fe904
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 497 deletions.
1 change: 0 additions & 1 deletion crates/ruff_linter/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ mod tests {
Ok(())
}

#[test_case(Rule::IsLiteral, Path::new("constant_literals.py"))]
#[test_case(Rule::RedundantBackslash, Path::new("E502.py"))]
#[test_case(Rule::TooManyNewlinesAtEndOfFile, Path::new("W391_0.py"))]
#[test_case(Rule::TooManyNewlinesAtEndOfFile, Path::new("W391_1.py"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,375 @@ constant_literals.py:16:4: E712 [*] Avoid equality comparisons to `False`; use `
17 17 | pass
18 18 |
19 19 | named_var = []

constant_literals.py:20:4: F632 [*] Use `==` to compare constant literals
|
19 | named_var = []
20 | if [] is []: # F632 (fix)
| ^^^^^^^^ F632
21 | pass
22 | if named_var is []: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
17 17 | pass
18 18 |
19 19 | named_var = []
20 |-if [] is []: # F632 (fix)
20 |+if [] == []: # F632 (fix)
21 21 | pass
22 22 | if named_var is []: # F632 (fix)
23 23 | pass

constant_literals.py:22:4: F632 [*] Use `==` to compare constant literals
|
20 | if [] is []: # F632 (fix)
21 | pass
22 | if named_var is []: # F632 (fix)
| ^^^^^^^^^^^^^^^ F632
23 | pass
24 | if [] is named_var: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
19 19 | named_var = []
20 20 | if [] is []: # F632 (fix)
21 21 | pass
22 |-if named_var is []: # F632 (fix)
22 |+if named_var == []: # F632 (fix)
23 23 | pass
24 24 | if [] is named_var: # F632 (fix)
25 25 | pass

constant_literals.py:24:4: F632 [*] Use `==` to compare constant literals
|
22 | if named_var is []: # F632 (fix)
23 | pass
24 | if [] is named_var: # F632 (fix)
| ^^^^^^^^^^^^^^^ F632
25 | pass
26 | if named_var is [1]: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
21 21 | pass
22 22 | if named_var is []: # F632 (fix)
23 23 | pass
24 |-if [] is named_var: # F632 (fix)
24 |+if [] == named_var: # F632 (fix)
25 25 | pass
26 26 | if named_var is [1]: # F632 (fix)
27 27 | pass

constant_literals.py:26:4: F632 [*] Use `==` to compare constant literals
|
24 | if [] is named_var: # F632 (fix)
25 | pass
26 | if named_var is [1]: # F632 (fix)
| ^^^^^^^^^^^^^^^^ F632
27 | pass
28 | if [1] is named_var: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
23 23 | pass
24 24 | if [] is named_var: # F632 (fix)
25 25 | pass
26 |-if named_var is [1]: # F632 (fix)
26 |+if named_var == [1]: # F632 (fix)
27 27 | pass
28 28 | if [1] is named_var: # F632 (fix)
29 29 | pass

constant_literals.py:28:4: F632 [*] Use `==` to compare constant literals
|
26 | if named_var is [1]: # F632 (fix)
27 | pass
28 | if [1] is named_var: # F632 (fix)
| ^^^^^^^^^^^^^^^^ F632
29 | pass
30 | if named_var is [i for i in [1]]: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
25 25 | pass
26 26 | if named_var is [1]: # F632 (fix)
27 27 | pass
28 |-if [1] is named_var: # F632 (fix)
28 |+if [1] == named_var: # F632 (fix)
29 29 | pass
30 30 | if named_var is [i for i in [1]]: # F632 (fix)
31 31 | pass

constant_literals.py:30:4: F632 [*] Use `==` to compare constant literals
|
28 | if [1] is named_var: # F632 (fix)
29 | pass
30 | if named_var is [i for i in [1]]: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F632
31 | pass
|
= help: Replace `is` with `==`

Safe fix
27 27 | pass
28 28 | if [1] is named_var: # F632 (fix)
29 29 | pass
30 |-if named_var is [i for i in [1]]: # F632 (fix)
30 |+if named_var == [i for i in [1]]: # F632 (fix)
31 31 | pass
32 32 |
33 33 | named_var = {}

constant_literals.py:34:4: F632 [*] Use `==` to compare constant literals
|
33 | named_var = {}
34 | if {} is {}: # F632 (fix)
| ^^^^^^^^ F632
35 | pass
36 | if named_var is {}: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
31 31 | pass
32 32 |
33 33 | named_var = {}
34 |-if {} is {}: # F632 (fix)
34 |+if {} == {}: # F632 (fix)
35 35 | pass
36 36 | if named_var is {}: # F632 (fix)
37 37 | pass

constant_literals.py:36:4: F632 [*] Use `==` to compare constant literals
|
34 | if {} is {}: # F632 (fix)
35 | pass
36 | if named_var is {}: # F632 (fix)
| ^^^^^^^^^^^^^^^ F632
37 | pass
38 | if {} is named_var: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
33 33 | named_var = {}
34 34 | if {} is {}: # F632 (fix)
35 35 | pass
36 |-if named_var is {}: # F632 (fix)
36 |+if named_var == {}: # F632 (fix)
37 37 | pass
38 38 | if {} is named_var: # F632 (fix)
39 39 | pass

constant_literals.py:38:4: F632 [*] Use `==` to compare constant literals
|
36 | if named_var is {}: # F632 (fix)
37 | pass
38 | if {} is named_var: # F632 (fix)
| ^^^^^^^^^^^^^^^ F632
39 | pass
40 | if named_var is {1}: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
35 35 | pass
36 36 | if named_var is {}: # F632 (fix)
37 37 | pass
38 |-if {} is named_var: # F632 (fix)
38 |+if {} == named_var: # F632 (fix)
39 39 | pass
40 40 | if named_var is {1}: # F632 (fix)
41 41 | pass

constant_literals.py:40:4: F632 [*] Use `==` to compare constant literals
|
38 | if {} is named_var: # F632 (fix)
39 | pass
40 | if named_var is {1}: # F632 (fix)
| ^^^^^^^^^^^^^^^^ F632
41 | pass
42 | if {1} is named_var: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
37 37 | pass
38 38 | if {} is named_var: # F632 (fix)
39 39 | pass
40 |-if named_var is {1}: # F632 (fix)
40 |+if named_var == {1}: # F632 (fix)
41 41 | pass
42 42 | if {1} is named_var: # F632 (fix)
43 43 | pass

constant_literals.py:42:4: F632 [*] Use `==` to compare constant literals
|
40 | if named_var is {1}: # F632 (fix)
41 | pass
42 | if {1} is named_var: # F632 (fix)
| ^^^^^^^^^^^^^^^^ F632
43 | pass
44 | if named_var is {i for i in [1]}: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
39 39 | pass
40 40 | if named_var is {1}: # F632 (fix)
41 41 | pass
42 |-if {1} is named_var: # F632 (fix)
42 |+if {1} == named_var: # F632 (fix)
43 43 | pass
44 44 | if named_var is {i for i in [1]}: # F632 (fix)
45 45 | pass

constant_literals.py:44:4: F632 [*] Use `==` to compare constant literals
|
42 | if {1} is named_var: # F632 (fix)
43 | pass
44 | if named_var is {i for i in [1]}: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F632
45 | pass
|
= help: Replace `is` with `==`

Safe fix
41 41 | pass
42 42 | if {1} is named_var: # F632 (fix)
43 43 | pass
44 |-if named_var is {i for i in [1]}: # F632 (fix)
44 |+if named_var == {i for i in [1]}: # F632 (fix)
45 45 | pass
46 46 |
47 47 | named_var = {1: 1}

constant_literals.py:48:4: F632 [*] Use `==` to compare constant literals
|
47 | named_var = {1: 1}
48 | if {1: 1} is {1: 1}: # F632 (fix)
| ^^^^^^^^^^^^^^^^ F632
49 | pass
50 | if named_var is {1: 1}: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
45 45 | pass
46 46 |
47 47 | named_var = {1: 1}
48 |-if {1: 1} is {1: 1}: # F632 (fix)
48 |+if {1: 1} == {1: 1}: # F632 (fix)
49 49 | pass
50 50 | if named_var is {1: 1}: # F632 (fix)
51 51 | pass

constant_literals.py:50:4: F632 [*] Use `==` to compare constant literals
|
48 | if {1: 1} is {1: 1}: # F632 (fix)
49 | pass
50 | if named_var is {1: 1}: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^ F632
51 | pass
52 | if {1: 1} is named_var: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
47 47 | named_var = {1: 1}
48 48 | if {1: 1} is {1: 1}: # F632 (fix)
49 49 | pass
50 |-if named_var is {1: 1}: # F632 (fix)
50 |+if named_var == {1: 1}: # F632 (fix)
51 51 | pass
52 52 | if {1: 1} is named_var: # F632 (fix)
53 53 | pass

constant_literals.py:52:4: F632 [*] Use `==` to compare constant literals
|
50 | if named_var is {1: 1}: # F632 (fix)
51 | pass
52 | if {1: 1} is named_var: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^ F632
53 | pass
54 | if named_var is {1: 1}: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
49 49 | pass
50 50 | if named_var is {1: 1}: # F632 (fix)
51 51 | pass
52 |-if {1: 1} is named_var: # F632 (fix)
52 |+if {1: 1} == named_var: # F632 (fix)
53 53 | pass
54 54 | if named_var is {1: 1}: # F632 (fix)
55 55 | pass

constant_literals.py:54:4: F632 [*] Use `==` to compare constant literals
|
52 | if {1: 1} is named_var: # F632 (fix)
53 | pass
54 | if named_var is {1: 1}: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^ F632
55 | pass
56 | if {1: 1} is named_var: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
51 51 | pass
52 52 | if {1: 1} is named_var: # F632 (fix)
53 53 | pass
54 |-if named_var is {1: 1}: # F632 (fix)
54 |+if named_var == {1: 1}: # F632 (fix)
55 55 | pass
56 56 | if {1: 1} is named_var: # F632 (fix)
57 57 | pass

constant_literals.py:56:4: F632 [*] Use `==` to compare constant literals
|
54 | if named_var is {1: 1}: # F632 (fix)
55 | pass
56 | if {1: 1} is named_var: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^ F632
57 | pass
58 | if named_var is {i: 1 for i in [1]}: # F632 (fix)
|
= help: Replace `is` with `==`

Safe fix
53 53 | pass
54 54 | if named_var is {1: 1}: # F632 (fix)
55 55 | pass
56 |-if {1: 1} is named_var: # F632 (fix)
56 |+if {1: 1} == named_var: # F632 (fix)
57 57 | pass
58 58 | if named_var is {i: 1 for i in [1]}: # F632 (fix)
59 59 | pass

constant_literals.py:58:4: F632 [*] Use `==` to compare constant literals
|
56 | if {1: 1} is named_var: # F632 (fix)
57 | pass
58 | if named_var is {i: 1 for i in [1]}: # F632 (fix)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F632
59 | pass
|
= help: Replace `is` with `==`

Safe fix
55 55 | pass
56 56 | if {1: 1} is named_var: # F632 (fix)
57 57 | pass
58 |-if named_var is {i: 1 for i in [1]}: # F632 (fix)
58 |+if named_var == {i: 1 for i in [1]}: # F632 (fix)
59 59 | pass
60 60 |
61 61 | ###
Loading

0 comments on commit d0fe904

Please sign in to comment.