---
source: crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs
---
C416.py:6:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
  |
4 | d = {"a": 1, "b": 2, "c": 3}
5 | 
6 | [i for i in x]
  | ^^^^^^^^^^^^^^ C416
7 | {i for i in x}
8 | {k: v for k, v in y}
  |
  = help: Rewrite using `list()`

ℹ Unsafe fix
3 3 | z = [(1,), (2,), (3,)]
4 4 | d = {"a": 1, "b": 2, "c": 3}
5 5 | 
6   |-[i for i in x]
  6 |+list(x)
7 7 | {i for i in x}
8 8 | {k: v for k, v in y}
9 9 | {k: v for k, v in d.items()}

C416.py:7:1: C416 [*] Unnecessary `set` comprehension (rewrite using `set()`)
  |
6 | [i for i in x]
7 | {i for i in x}
  | ^^^^^^^^^^^^^^ C416
8 | {k: v for k, v in y}
9 | {k: v for k, v in d.items()}
  |
  = help: Rewrite using `set()`

ℹ Unsafe fix
4 4 | d = {"a": 1, "b": 2, "c": 3}
5 5 | 
6 6 | [i for i in x]
7   |-{i for i in x}
  7 |+set(x)
8 8 | {k: v for k, v in y}
9 9 | {k: v for k, v in d.items()}
10 10 | [(k, v) for k, v in d.items()]

C416.py:8:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
   |
 6 | [i for i in x]
 7 | {i for i in x}
 8 | {k: v for k, v in y}
   | ^^^^^^^^^^^^^^^^^^^^ C416
 9 | {k: v for k, v in d.items()}
10 | [(k, v) for k, v in d.items()]
   |
   = help: Rewrite using `dict()`

ℹ Unsafe fix
5 5 | 
6 6 | [i for i in x]
7 7 | {i for i in x}
8   |-{k: v for k, v in y}
  8 |+dict(y)
9 9 | {k: v for k, v in d.items()}
10 10 | [(k, v) for k, v in d.items()]
11 11 | {k: (a, b) for k, (a, b) in d.items()}

C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
   |
 7 | {i for i in x}
 8 | {k: v for k, v in y}
 9 | {k: v for k, v in d.items()}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C416
10 | [(k, v) for k, v in d.items()]
11 | {k: (a, b) for k, (a, b) in d.items()}
   |
   = help: Rewrite using `dict()`

ℹ Unsafe fix
6  6  | [i for i in x]
7  7  | {i for i in x}
8  8  | {k: v for k, v in y}
9     |-{k: v for k, v in d.items()}
   9  |+dict(d.items())
10 10 | [(k, v) for k, v in d.items()]
11 11 | {k: (a, b) for k, (a, b) in d.items()}
12 12 | 

C416.py:10:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
   |
 8 | {k: v for k, v in y}
 9 | {k: v for k, v in d.items()}
10 | [(k, v) for k, v in d.items()]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C416
11 | {k: (a, b) for k, (a, b) in d.items()}
   |
   = help: Rewrite using `list()`

ℹ Unsafe fix
7  7  | {i for i in x}
8  8  | {k: v for k, v in y}
9  9  | {k: v for k, v in d.items()}
10    |-[(k, v) for k, v in d.items()]
   10 |+list(d.items())
11 11 | {k: (a, b) for k, (a, b) in d.items()}
12 12 | 
13 13 | [i for i, in z]

C416.py:11:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`)
   |
 9 | {k: v for k, v in d.items()}
10 | [(k, v) for k, v in d.items()]
11 | {k: (a, b) for k, (a, b) in d.items()}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C416
12 | 
13 | [i for i, in z]
   |
   = help: Rewrite using `dict()`

ℹ Unsafe fix
8  8  | {k: v for k, v in y}
9  9  | {k: v for k, v in d.items()}
10 10 | [(k, v) for k, v in d.items()]
11    |-{k: (a, b) for k, (a, b) in d.items()}
   11 |+dict(d.items())
12 12 | 
13 13 | [i for i, in z]
14 14 | [i for i, j in y]

C416.py:24:70: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
   |
23 | # Regression test for: https://github.com/astral-sh/ruff/issues/7196
24 | any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in[t for t in SymbolType])
   |                                                                      ^^^^^^^^^^^^^^^^^^^^^^^ C416
   |
   = help: Rewrite using `list()`

ℹ Unsafe fix
21 21 | {k: v if v else None for k, v in y}
22 22 | 
23 23 | # Regression test for: https://github.com/astral-sh/ruff/issues/7196
24    |-any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in[t for t in SymbolType])
   24 |+any(len(symbol_table.get_by_type(symbol_type)) > 0 for symbol_type in list(SymbolType))


