---
source: crates/ruff_linter/src/rules/perflint/mod.rs
---
PERF102 [*] When using only the values of a dict use the `values()` method
 --> PERF102.py:5:21
  |
4 | def f():
5 |     for _, value in some_dict.items():  # PERF102
  |                     ^^^^^^^^^^^^^^^
6 |         print(value)
  |
help: Replace `.items()` with `.values()`
  |
4 | def f():
  -     for _, value in some_dict.items():  # PERF102
5 +     for value in some_dict.values():  # PERF102
6 |         print(value)
  |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:10:19
   |
 9 | def f():
10 |     for key, _ in some_dict.items():  # PERF102
   |                   ^^^^^^^^^^^^^^^
11 |         print(key)
   |
help: Replace `.items()` with `.keys()`
   |
9  | def f():
   -     for key, _ in some_dict.items():  # PERF102
10 +     for key in some_dict.keys():  # PERF102
11 |         print(key)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:15:30
   |
14 | def f():
15 |     for weird_arg_name, _ in some_dict.items():  # PERF102
   |                              ^^^^^^^^^^^^^^^
16 |         print(weird_arg_name)
   |
help: Replace `.items()` with `.keys()`
   |
14 | def f():
   -     for weird_arg_name, _ in some_dict.items():  # PERF102
15 +     for weird_arg_name in some_dict.keys():  # PERF102
16 |         print(weird_arg_name)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:20:25
   |
19 | def f():
20 |     for name, (_, _) in some_dict.items():  # PERF102
   |                         ^^^^^^^^^^^^^^^
21 |         print(name)
   |
help: Replace `.items()` with `.keys()`
   |
19 | def f():
   -     for name, (_, _) in some_dict.items():  # PERF102
20 +     for name in some_dict.keys():  # PERF102
21 |         print(name)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:30:30
   |
29 | def f():
30 |     for (key1, _), (_, _) in some_dict.items():  # PERF102
   |                              ^^^^^^^^^^^^^^^
31 |         print(key1)
   |
help: Replace `.items()` with `.keys()`
   |
29 | def f():
   -     for (key1, _), (_, _) in some_dict.items():  # PERF102
30 +     for (key1, _) in some_dict.keys():  # PERF102
31 |         print(key1)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the values of a dict use the `values()` method
  --> PERF102.py:35:36
   |
34 | def f():
35 |     for (_, (_, _)), (value, _) in some_dict.items():  # PERF102
   |                                    ^^^^^^^^^^^^^^^
36 |         print(value)
   |
help: Replace `.items()` with `.values()`
   |
34 | def f():
   -     for (_, (_, _)), (value, _) in some_dict.items():  # PERF102
35 +     for (value, _) in some_dict.values():  # PERF102
36 |         print(value)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:50:32
   |
49 | def f():
50 |     for ((_, key2), (_, _)) in some_dict.items():  # PERF102
   |                                ^^^^^^^^^^^^^^^
51 |         print(key2)
   |
help: Replace `.items()` with `.keys()`
   |
49 | def f():
   -     for ((_, key2), (_, _)) in some_dict.items():  # PERF102
50 +     for (_, key2) in some_dict.keys():  # PERF102
51 |         print(key2)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:85:25
   |
84 | def f():
85 |     for name, (_, _) in (some_function()).items():  # PERF102
   |                         ^^^^^^^^^^^^^^^^^^^^^^^
86 |         print(name)
   |
help: Replace `.items()` with `.keys()`
   |
84 | def f():
   -     for name, (_, _) in (some_function()).items():  # PERF102
85 +     for name in (some_function()).keys():  # PERF102
86 |         print(name)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:90:25
   |
89 | def f():
90 |     for name, (_, _) in (some_function().some_attribute).items():  # PERF102
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91 |         print(name)
   |
help: Replace `.items()` with `.keys()`
   |
89 | def f():
   -     for name, (_, _) in (some_function().some_attribute).items():  # PERF102
90 +     for name in (some_function().some_attribute).keys():  # PERF102
91 |         print(name)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
  --> PERF102.py:95:31
   |
94 | def f():
95 |     for name, unused_value in some_dict.items():  # PERF102
   |                               ^^^^^^^^^^^^^^^
96 |         print(name)
   |
help: Replace `.items()` with `.keys()`
   |
94 | def f():
   -     for name, unused_value in some_dict.items():  # PERF102
95 +     for name in some_dict.keys():  # PERF102
96 |         print(name)
   |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the values of a dict use the `values()` method
   --> PERF102.py:100:31
    |
 99 | def f():
100 |     for unused_name, value in some_dict.items():  # PERF102
    |                               ^^^^^^^^^^^^^^^
101 |         print(value)
    |
help: Replace `.items()` with `.values()`
    |
99  | def f():
    -     for unused_name, value in some_dict.items():  # PERF102
100 +     for value in some_dict.values():  # PERF102
101 |         print(value)
    |
note: This is an unsafe fix and may change runtime behavior

PERF102 [*] When using only the keys of a dict use the `keys()` method
   --> PERF102.py:106:16
    |
104 | # Regression test for: https://github.com/astral-sh/ruff/issues/7097
105 | def _create_context(name_to_value):
106 |     for(B,D)in A.items():
    |                ^^^^^^^
107 |         if(C:=name_to_value.get(B.name)):A.run(B.set,C)
    |
help: Replace `.items()` with `.keys()`
    |
105 | def _create_context(name_to_value):
    -     for(B,D)in A.items():
106 +     for B in A.keys():
107 |         if(C:=name_to_value.get(B.name)):A.run(B.set,C)
    |
note: This is an unsafe fix and may change runtime behavior
