---
source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs
---
C403.py:1:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
  |
1 | s = set([x for x in range(3)])
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ C403
2 | s = set(
3 |     [x for x in range(3)]
  |
  = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
1   |-s = set([x for x in range(3)])
  1 |+s = {x for x in range(3)}
2 2 | s = set(
3 3 |     [x for x in range(3)]
4 4 | )

C403.py:2:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
  |
1 |   s = set([x for x in range(3)])
2 |   s = set(
  |  _____^
3 | |     [x for x in range(3)]
4 | | )
  | |_^ C403
5 |   
6 |   s = f"{set([x for x in 'ab'])}"
  |
  = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
1 1 | s = set([x for x in range(3)])
2   |-s = set(
3   |-    [x for x in range(3)]
4   |-)
  2 |+s = {
  3 |+    x for x in range(3)
  4 |+}
5 5 | 
6 6 | s = f"{set([x for x in 'ab'])}"
7 7 | s = f'{set([x for x in "ab"])}'

C403.py:6:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
  |
4 | )
5 | 
6 | s = f"{set([x for x in 'ab'])}"
  |        ^^^^^^^^^^^^^^^^^^^^^^ C403
7 | s = f'{set([x for x in "ab"])}'
  |
  = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
3 3 |     [x for x in range(3)]
4 4 | )
5 5 | 
6   |-s = f"{set([x for x in 'ab'])}"
  6 |+s = f"{ {x for x in 'ab'} }"
7 7 | s = f'{set([x for x in "ab"])}'
8 8 | 
9 9 | def f(x):

C403.py:7:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
  |
6 | s = f"{set([x for x in 'ab'])}"
7 | s = f'{set([x for x in "ab"])}'
  |        ^^^^^^^^^^^^^^^^^^^^^^ C403
8 | 
9 | def f(x):
  |
  = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
4 4 | )
5 5 | 
6 6 | s = f"{set([x for x in 'ab'])}"
7   |-s = f'{set([x for x in "ab"])}'
  7 |+s = f'{ {x for x in "ab"} }'
8 8 | 
9 9 | def f(x):
10 10 |     return x

C403.py:12:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
10 |     return x
11 | 
12 | s = f"{set([f(x) for x in 'ab'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^ C403
13 | 
14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
9  9  | def f(x):
10 10 |     return x
11 11 | 
12    |-s = f"{set([f(x) for x in 'ab'])}"
   12 |+s = f"{ {f(x) for x in 'ab'} }"
13 13 | 
14 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
15 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"

C403.py:14:9: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
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']) }"
   |         ^^^^^^^^^^^^^^^^^^^^^^ C403
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
11 11 | 
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 | 
14    |-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 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
16 16 | 
17 17 | s = set(  # comment

C403.py:14:34: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
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']) }"
   |                                  ^^^^^^^^^^^^^^^^^^^^^^ C403
15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
11 11 | 
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 | 
14    |-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 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
16 16 | 
17 17 | s = set(  # comment

C403.py:15:8: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
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'])}"
   |        ^^^^^^^^^^^^^^^^^^^^^^ C403
16 | 
17 | s = set(  # comment
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 | 
14 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'])}"
   15 |+s = f"{ {x for x in 'ab'} | set([x for x in 'ab'])}"
16 16 | 
17 17 | s = set(  # comment
18 18 |     [x for x in range(3)]

C403.py:15:33: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
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'])}"
   |                                 ^^^^^^^^^^^^^^^^^^^^^^ C403
16 | 
17 | s = set(  # comment
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
12 12 | s = f"{set([f(x) for x in 'ab'])}"
13 13 | 
14 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'])}"
   15 |+s = f"{set([x for x in 'ab']) | {x for x in 'ab'} }"
16 16 | 
17 17 | s = set(  # comment
18 18 |     [x for x in range(3)]

C403.py:17:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
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 | | )
   | |_^ C403
20 |   
21 |   s = set([  # comment
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
14 14 | s = f"{ set([x for x in 'ab']) | set([x for x in 'ab']) }"
15 15 | s = f"{set([x for x in 'ab']) | set([x for x in 'ab'])}"
16 16 | 
17    |-s = set(  # comment
18    |-    [x for x in range(3)]
19    |-)
   17 |+s = {  # comment
   18 |+    x for x in range(3)
   19 |+}
20 20 | 
21 21 | s = set([  # comment
22 22 |     x for x in range(3)

C403.py:21:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
   |
19 |   )
20 |   
21 |   s = set([  # comment
   |  _____^
22 | |     x for x in range(3)
23 | | ])
   | |__^ C403
   |
   = help: Rewrite as a `set` comprehension

ℹ Unsafe fix
18 18 |     [x for x in range(3)]
19 19 | )
20 20 | 
21    |-s = set([  # comment
   21 |+s = {  # comment
22 22 |     x for x in range(3)
23    |-])
   23 |+}


