---
source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs
---
C419 [*] Unnecessary list comprehension
 --> C419.py:1:5
  |
1 | any([x.id for x in bar])
  |     ^^^^^^^^^^^^^^^^^^^
2 | all([x.id for x in bar])
3 | any(  # first comment
  |
help: Remove unnecessary comprehension
  |
  - any([x.id for x in bar])
1 + any(x.id for x in bar)
2 | all([x.id for x in bar])
  |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary list comprehension
 --> C419.py:2:5
  |
1 | any([x.id for x in bar])
2 | all([x.id for x in bar])
  |     ^^^^^^^^^^^^^^^^^^^
3 | any(  # first comment
4 |     [x.id for x in bar],  # second comment
  |
help: Remove unnecessary comprehension
  |
1 | any([x.id for x in bar])
  - all([x.id for x in bar])
2 + all(x.id for x in bar)
3 | any(  # first comment
  |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary list comprehension
 --> C419.py:4:5
  |
2 | all([x.id for x in bar])
3 | any(  # first comment
4 |     [x.id for x in bar],  # second comment
  |     ^^^^^^^^^^^^^^^^^^^
5 | )  # third comment
6 | all(  # first comment
  |
help: Remove unnecessary comprehension
  |
3 | any(  # first comment
  -     [x.id for x in bar],  # second comment
4 +     x.id for x in bar  # second comment
5 | )  # third comment
  |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary list comprehension
 --> C419.py:7:5
  |
5 | )  # third comment
6 | all(  # first comment
7 |     [x.id for x in bar],  # second comment
  |     ^^^^^^^^^^^^^^^^^^^
8 | )  # third comment
9 | any({x.id for x in bar})
  |
help: Remove unnecessary comprehension
  |
6 | all(  # first comment
  -     [x.id for x in bar],  # second comment
7 +     x.id for x in bar  # second comment
8 | )  # third comment
  |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary set comprehension
  --> C419.py:9:5
   |
 7 |     [x.id for x in bar],  # second comment
 8 | )  # third comment
 9 | any({x.id for x in bar})
   |     ^^^^^^^^^^^^^^^^^^^
10 |
11 | # OK
   |
help: Remove unnecessary comprehension
   |
8  | )  # third comment
   - any({x.id for x in bar})
9  + any(x.id for x in bar)
10 |
   |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary list comprehension
  --> C419.py:28:5
   |
26 |   # Special comment handling
27 |   any(
28 | /     [  # lbracket comment
29 | |         # second line comment
30 | |         i.bit_count()
31 | |         # random middle comment
32 | |         for i in range(5)  # rbracket comment
33 | |     ]  # rpar comment
   | |_____^
34 |       # trailing comment
35 |   )
   |
help: Remove unnecessary comprehension
   |
27 | any(
   -     [  # lbracket comment
   -         # second line comment
   -         i.bit_count()
28 +     # lbracket comment
29 +     # second line comment
30 +     i.bit_count()
31 |         # random middle comment
   -         for i in range(5)  # rbracket comment
   -     ]  # rpar comment
32 +         for i in range(5)  # rbracket comment  # rpar comment
33 |     # trailing comment
   |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary list comprehension
  --> C419.py:39:5
   |
37 |   # Weird case where the function call, opening bracket, and comment are all
38 |   # on the same line.
39 |   any([  # lbracket comment
   |  _____^
40 | |         # second line comment
41 | |         i.bit_count() for i in range(5)  # rbracket comment
42 | |     ]  # rpar comment
   | |_____^
43 |   )
   |
help: Remove unnecessary comprehension
   |
38 | # on the same line.
   - any([  # lbracket comment
   -         # second line comment
   -         i.bit_count() for i in range(5)  # rbracket comment
   -     ]  # rpar comment
39 + any(
40 + # lbracket comment
41 + # second line comment
42 + i.bit_count() for i in range(5)  # rbracket comment  # rpar comment
43 | )
   |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary set comprehension
  --> C419.py:49:5
   |
48 | # should be linted...
49 | any({x.id for x in bar})
   |     ^^^^^^^^^^^^^^^^^^^
50 | all({x.id for x in bar})
   |
help: Remove unnecessary comprehension
   |
48 | # should be linted...
   - any({x.id for x in bar})
49 + any(x.id for x in bar)
50 | all({x.id for x in bar})
   |
note: This is an unsafe fix and may change runtime behavior

C419 [*] Unnecessary set comprehension
  --> C419.py:50:5
   |
48 | # should be linted...
49 | any({x.id for x in bar})
50 | all({x.id for x in bar})
   |     ^^^^^^^^^^^^^^^^^^^
51 |
52 | # should be linted in preview...
   |
help: Remove unnecessary comprehension
   |
49 | any({x.id for x in bar})
   - all({x.id for x in bar})
50 + all(x.id for x in bar)
51 |
   |
note: This is an unsafe fix and may change runtime behavior
