---
source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs
---
C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
 --> C403.py:1:5
  |
1 | s = set([x for x in range(3)])
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 | s = set(
3 |     [x for x in range(3)]
  |
help: Rewrite as a set comprehension
  |
  - s = set([x for x in range(3)])
1 + s = {x for x in range(3)}
2 | s = set(
  |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
 --> C403.py:2:5
  |
1 |   s = set([x for x in range(3)])
2 |   s = set(
  |  _____^
3 | |     [x for x in range(3)]
4 | | )
  | |_^
5 |
6 |   s = f"{set([x for x in 'ab'])}"
  |
help: Rewrite as a set comprehension
  |
1 | s = set([x for x in range(3)])
  - s = set(
  -     [x for x in range(3)]
  - )
2 + s = {
3 +     x for x in range(3)
4 + }
5 |
  |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
 --> C403.py:6:8
  |
4 | )
5 |
6 | s = f"{set([x for x in 'ab'])}"
  |        ^^^^^^^^^^^^^^^^^^^^^^
7 | s = f'{set([x for x in "ab"])}'
  |
help: Rewrite as a set comprehension
  |
5 |
  - s = f"{set([x for x in 'ab'])}"
6 + s = f"{ {x for x in 'ab'} }"
7 | s = f'{set([x for x in "ab"])}'
  |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
 --> C403.py:7:8
  |
6 | s = f"{set([x for x in 'ab'])}"
7 | s = f'{set([x for x in "ab"])}'
  |        ^^^^^^^^^^^^^^^^^^^^^^
8 |
9 | def f(x):
  |
help: Rewrite as a set comprehension
  |
6 | s = f"{set([x for x in 'ab'])}"
  - s = f'{set([x for x in "ab"])}'
7 + s = f'{ {x for x in "ab"} }'
8 |
  |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:12:8
   |
10 |     return x
11 |
12 | s = f"{set([f(x) for x in 'ab'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^
13 |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |
help: Rewrite as a set comprehension
   |
11 |
   - s = f"{set([f(x) for x in 'ab'])}"
12 + s = f"{ {f(x) for x in 'ab'} }"
13 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:14:9
   |
12 | s = f"{set([f(x) for x in 'ab'])}"
13 |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |         ^^^^^^^^^^^^^^^^^^^^^^
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
help: Rewrite as a set comprehension
   |
13 |
   - s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
14 + s = f"{ {x for x in 'ab'} | set([x for x in 'ab']) }"
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:14:34
   |
12 | s = f"{set([f(x) for x in 'ab'])}"
13 |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |                                  ^^^^^^^^^^^^^^^^^^^^^^
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
help: Rewrite as a set comprehension
   |
13 |
   - s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
14 + s = f"{ set([x for x in 'ab']) | {x for x in 'ab'} }"
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:15:8
   |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^
16 |
17 | s = set(  # comment
   |
help: Rewrite as a set comprehension
   |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   - s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
15 + s = f"{ {x for x in 'ab'} | set([x for x in 'ab'])}"
16 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:15:33
   |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |                                 ^^^^^^^^^^^^^^^^^^^^^^
16 |
17 | s = set(  # comment
   |
help: Rewrite as a set comprehension
   |
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   - s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
15 + s = f"{set([x for x in 'ab']) | {x for x in 'ab'} }"
16 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:17:5
   |
15 |   s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
16 |
17 |   s = set(  # comment
   |  _____^
18 | |     [x for x in range(3)]
19 | | )
   | |_^
20 |
21 |   s = set([  # comment
   |
help: Rewrite as a set comprehension
   |
16 |
   - s = set(  # comment
   -     [x for x in range(3)]
   - )
17 + s = {  # comment
18 +     x for x in range(3)
19 + }
20 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:21:5
   |
19 |   )
20 |
21 |   s = set([  # comment
   |  _____^
22 | |     x for x in range(3)
23 | | ])
   | |__^
24 |
25 |   s = set(([x for x in range(3)]))
   |
help: Rewrite as a set comprehension
   |
20 |
   - s = set([  # comment
21 + s = {  # comment
22 |     x for x in range(3)
   - ])
23 + }
24 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:25:5
   |
23 | ])
24 |
25 | s = set(([x for x in range(3)]))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 |
27 | s = set(((([x for x in range(3)]))))
   |
help: Rewrite as a set comprehension
   |
24 |
   - s = set(([x for x in range(3)]))
25 + s = {x for x in range(3)}
26 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:27:5
   |
25 | s = set(([x for x in range(3)]))
26 |
27 | s = set(((([x for x in range(3)]))))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28 |
29 | s = set( # outer set comment
   |
help: Rewrite as a set comprehension
   |
26 |
   - s = set(((([x for x in range(3)]))))
27 + s = {x for x in range(3)}
28 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:29:5
   |
27 |   s = set(((([x for x in range(3)]))))
28 |
29 |   s = set( # outer set comment
   |  _____^
30 | | ( # inner paren comment - not preserved
31 | | ((
32 | | [ # comprehension comment
33 | |  x for x in range(3)]
34 | |  ))))
   | |_____^
35 |
36 |   # Test trailing comma case
   |
help: Rewrite as a set comprehension
   |
28 |
   - s = set( # outer set comment
   - ( # inner paren comment - not preserved
   - ((
   - [ # comprehension comment
   -  x for x in range(3)]
   -  ))))
29 + s = { # outer set comment
30 +  # comprehension comment
31 +  x for x in range(3)}
32 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:37:5
   |
36 | # Test trailing comma case
37 | s = set([x for x in range(3)],)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
38 |
39 | s = t"{set([x for x in 'ab'])}"
   |
help: Rewrite as a set comprehension
   |
36 | # Test trailing comma case
   - s = set([x for x in range(3)],)
37 + s = {x for x in range(3)}
38 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:39:8
   |
37 | s = set([x for x in range(3)],)
38 |
39 | s = t"{set([x for x in 'ab'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^
40 | s = t'{set([x for x in "ab"])}'
   |
help: Rewrite as a set comprehension
   |
38 |
   - s = t"{set([x for x in 'ab'])}"
39 + s = t"{ {x for x in 'ab'} }"
40 | s = t'{set([x for x in "ab"])}'
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:40:8
   |
39 | s = t"{set([x for x in 'ab'])}"
40 | s = t'{set([x for x in "ab"])}'
   |        ^^^^^^^^^^^^^^^^^^^^^^
41 |
42 | def f(x):
   |
help: Rewrite as a set comprehension
   |
39 | s = t"{set([x for x in 'ab'])}"
   - s = t'{set([x for x in "ab"])}'
40 + s = t'{ {x for x in "ab"} }'
41 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:45:8
   |
43 |     return x
44 |
45 | s = t"{set([f(x) for x in 'ab'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^
46 |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |
help: Rewrite as a set comprehension
   |
44 |
   - s = t"{set([f(x) for x in 'ab'])}"
45 + s = t"{ {f(x) for x in 'ab'} }"
46 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:47:9
   |
45 | s = t"{set([f(x) for x in 'ab'])}"
46 |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |         ^^^^^^^^^^^^^^^^^^^^^^
48 | s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
help: Rewrite as a set comprehension
   |
46 |
   - s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
47 + s = t"{ {x for x in 'ab'} | set([x for x in 'ab']) }"
48 | s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:47:34
   |
45 | s = t"{set([f(x) for x in 'ab'])}"
46 |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |                                  ^^^^^^^^^^^^^^^^^^^^^^
48 | s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
help: Rewrite as a set comprehension
   |
46 |
   - s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
47 + s = t"{ set([x for x in 'ab']) | {x for x in 'ab'} }"
48 | s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:48:8
   |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
48 | s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^
   |
help: Rewrite as a set comprehension
   |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   - s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
48 + s = t"{ {x for x in 'ab'} | set([x for x in 'ab'])}"
49 |
   |
note: This is an unsafe fix and may change runtime behavior

C403 [*] Unnecessary list comprehension (rewrite as a set comprehension)
  --> C403.py:48:33
   |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
48 | s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |                                 ^^^^^^^^^^^^^^^^^^^^^^
   |
help: Rewrite as a set comprehension
   |
47 | s = t"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   - s = t"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
48 + s = t"{set([x for x in 'ab']) | {x for x in 'ab'} }"
49 |
   |
note: This is an unsafe fix and may change runtime behavior
