---
source: crates/ruff_linter/src/rules/perflint/mod.rs
---
PERF101.py:7:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
  |
5 | foo_int = 123
6 | 
7 | for i in list(foo_tuple):  # PERF101
  |          ^^^^^^^^^^^^^^^ PERF101
8 |     pass
  |
  = help: Remove `list()` cast

ℹ Safe fix
4 4 | foo_dict = {1: 2, 3: 4}
5 5 | foo_int = 123
6 6 | 
7   |-for i in list(foo_tuple):  # PERF101
  7 |+for i in foo_tuple:  # PERF101
8 8 |     pass
9 9 | 
10 10 | for i in list(foo_list):  # PERF101

PERF101.py:10:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
 8 |     pass
 9 | 
10 | for i in list(foo_list):  # PERF101
   |          ^^^^^^^^^^^^^^ PERF101
11 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
7  7  | for i in list(foo_tuple):  # PERF101
8  8  |     pass
9  9  | 
10    |-for i in list(foo_list):  # PERF101
   10 |+for i in foo_list:  # PERF101
11 11 |     pass
12 12 | 
13 13 | for i in list(foo_set):  # PERF101

PERF101.py:13:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
11 |     pass
12 | 
13 | for i in list(foo_set):  # PERF101
   |          ^^^^^^^^^^^^^ PERF101
14 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
10 10 | for i in list(foo_list):  # PERF101
11 11 |     pass
12 12 | 
13    |-for i in list(foo_set):  # PERF101
   13 |+for i in foo_set:  # PERF101
14 14 |     pass
15 15 | 
16 16 | for i in list((1, 2, 3)):  # PERF101

PERF101.py:16:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
14 |     pass
15 | 
16 | for i in list((1, 2, 3)):  # PERF101
   |          ^^^^^^^^^^^^^^^ PERF101
17 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
13 13 | for i in list(foo_set):  # PERF101
14 14 |     pass
15 15 | 
16    |-for i in list((1, 2, 3)):  # PERF101
   16 |+for i in (1, 2, 3):  # PERF101
17 17 |     pass
18 18 | 
19 19 | for i in list([1, 2, 3]):  # PERF101

PERF101.py:19:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
17 |     pass
18 | 
19 | for i in list([1, 2, 3]):  # PERF101
   |          ^^^^^^^^^^^^^^^ PERF101
20 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
16 16 | for i in list((1, 2, 3)):  # PERF101
17 17 |     pass
18 18 | 
19    |-for i in list([1, 2, 3]):  # PERF101
   19 |+for i in [1, 2, 3]:  # PERF101
20 20 |     pass
21 21 | 
22 22 | for i in list({1, 2, 3}):  # PERF101

PERF101.py:22:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
20 |     pass
21 | 
22 | for i in list({1, 2, 3}):  # PERF101
   |          ^^^^^^^^^^^^^^^ PERF101
23 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
19 19 | for i in list([1, 2, 3]):  # PERF101
20 20 |     pass
21 21 | 
22    |-for i in list({1, 2, 3}):  # PERF101
   22 |+for i in {1, 2, 3}:  # PERF101
23 23 |     pass
24 24 | 
25 25 | for i in list(

PERF101.py:25:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
23 |       pass
24 |   
25 |   for i in list(
   |  __________^
26 | |     {
27 | |     1,
28 | |     2,
29 | |     3,
30 | |     }
31 | | ):
   | |_^ PERF101
32 |       pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
22 22 | for i in list({1, 2, 3}):  # PERF101
23 23 |     pass
24 24 | 
25    |-for i in list(
26    |-    {
   25 |+for i in {
27 26 |     1,
28 27 |     2,
29 28 |     3,
30    |-    }
31    |-):
   29 |+    }:
32 30 |     pass
33 31 | 
34 32 | for i in list( # Comment

PERF101.py:34:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
32 |       pass
33 |   
34 |   for i in list( # Comment
   |  __________^
35 | |     {1, 2, 3}
36 | | ):  # PERF101
   | |_^ PERF101
37 |       pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
31 31 | ):
32 32 |     pass
33 33 | 
34    |-for i in list( # Comment
35    |-    {1, 2, 3}
36    |-):  # PERF101
   34 |+for i in {1, 2, 3}:  # PERF101
37 35 |     pass
38 36 | 
39 37 | for i in list(foo_dict):  # OK

PERF101.py:57:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
55 |     foo_list.append(i + 1)
56 | 
57 | for i in list(foo_list):  # PERF101
   |          ^^^^^^^^^^^^^^ PERF101
58 |     # Make sure we match the correct list
59 |     other_list.append(i + 1)
   |
   = help: Remove `list()` cast

ℹ Safe fix
54 54 | for i in list(foo_list):  # OK
55 55 |     foo_list.append(i + 1)
56 56 | 
57    |-for i in list(foo_list):  # PERF101
   57 |+for i in foo_list:  # PERF101
58 58 |     # Make sure we match the correct list
59 59 |     other_list.append(i + 1)
60 60 | 

PERF101.py:69:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
67 | x, y, nested_tuple = (1, 2, (3, 4, 5))
68 | 
69 | for i in list(nested_tuple):  # PERF101
   |          ^^^^^^^^^^^^^^^^^^ PERF101
70 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
66 66 | 
67 67 | x, y, nested_tuple = (1, 2, (3, 4, 5))
68 68 | 
69    |-for i in list(nested_tuple):  # PERF101
   69 |+for i in nested_tuple:  # PERF101
70 70 |     pass
71 71 | 
72 72 | for i in list(foo_list):  # OK

PERF101.py:86:10: PERF101 [*] Do not cast an iterable to `list` before iterating over it
   |
84 | import builtins
85 | 
86 | for i in builtins.list(nested_tuple):  # PERF101
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PERF101
87 |     pass
   |
   = help: Remove `list()` cast

ℹ Safe fix
83 83 | 
84 84 | import builtins
85 85 | 
86    |-for i in builtins.list(nested_tuple):  # PERF101
   86 |+for i in nested_tuple:  # PERF101
87 87 |     pass
