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

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

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

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

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

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

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

PERF101 [*] Do not cast an iterable to `list` before iterating over it
  --> PERF101.py:34:10
   |
32 |       pass
33 |
34 |   for i in list( # Comment
   |  __________^
35 | |     {1, 2, 3}
36 | | ):  # PERF101
   | |_^
37 |       pass
   |
help: Remove `list()` cast
   |
33 |
   - for i in list( # Comment
   -     {1, 2, 3}
   - ):  # PERF101
34 + for i in {1, 2, 3}:  # PERF101
35 |     pass
   |
note: This is an unsafe fix and may change runtime behavior

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

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

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

PERF101 [*] Do not cast an iterable to `list` before iterating over it
  --> PERF101.py:91:9
   |
89 | # https://github.com/astral-sh/ruff/issues/18783
90 | items = (1, 2, 3)
91 | for i in(list)(items):
   |         ^^^^^^^^^^^^^
92 |     print(i)
   |
help: Remove `list()` cast
   |
90 | items = (1, 2, 3)
   - for i in(list)(items):
91 + for i in items:
92 |     print(i)
   |

PERF101 [*] Do not cast an iterable to `list` before iterating over it
   --> PERF101.py:96:10
    |
 94 |   # https://github.com/astral-sh/ruff/issues/18784
 95 |   items = (1, 2, 3)
 96 |   for i in (  # 1
    |  __________^
 97 | |     list  # 2
 98 | |     # 3
 99 | | )(  # 4
100 | |     items  # 5
101 | |     # 6
102 | | ):
    | |_^
103 |       print(i)
    |
help: Remove `list()` cast
   |
95 | items = (1, 2, 3)
   - for i in (  # 1
   -     list  # 2
   -     # 3
   - )(  # 4
   -     items  # 5
   -     # 6
   - ):
96 + for i in items:
97 |     print(i)
   |
note: This is an unsafe fix and may change runtime behavior
