---
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
snapshot_kind: text
---
SIM118.py:3:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
  |
1 | obj = {}
2 | 
3 | key in obj.keys()  # SIM118
  | ^^^^^^^^^^^^^^^^^ SIM118
4 | 
5 | key not in obj.keys()  # SIM118
  |
  = help: Remove `.keys()`

ℹ Safe fix
1 1 | obj = {}
2 2 | 
3   |-key in obj.keys()  # SIM118
  3 |+key in obj  # SIM118
4 4 | 
5 5 | key not in obj.keys()  # SIM118
6 6 | 

SIM118.py:5:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
  |
3 | key in obj.keys()  # SIM118
4 | 
5 | key not in obj.keys()  # SIM118
  | ^^^^^^^^^^^^^^^^^^^^^ SIM118
6 | 
7 | foo["bar"] in obj.keys()  # SIM118
  |
  = help: Remove `.keys()`

ℹ Safe fix
2 2 | 
3 3 | key in obj.keys()  # SIM118
4 4 | 
5   |-key not in obj.keys()  # SIM118
  5 |+key not in obj  # SIM118
6 6 | 
7 7 | foo["bar"] in obj.keys()  # SIM118
8 8 | 

SIM118.py:7:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
  |
5 | key not in obj.keys()  # SIM118
6 | 
7 | foo["bar"] in obj.keys()  # SIM118
  | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
8 | 
9 | foo["bar"] not in obj.keys()  # SIM118
  |
  = help: Remove `.keys()`

ℹ Safe fix
4 4 | 
5 5 | key not in obj.keys()  # SIM118
6 6 | 
7   |-foo["bar"] in obj.keys()  # SIM118
  7 |+foo["bar"] in obj  # SIM118
8 8 | 
9 9 | foo["bar"] not in obj.keys()  # SIM118
10 10 | 

SIM118.py:9:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
   |
 7 | foo["bar"] in obj.keys()  # SIM118
 8 | 
 9 | foo["bar"] not in obj.keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
10 | 
11 | foo['bar'] in obj.keys()  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
6  6  | 
7  7  | foo["bar"] in obj.keys()  # SIM118
8  8  | 
9     |-foo["bar"] not in obj.keys()  # SIM118
   9  |+foo["bar"] not in obj  # SIM118
10 10 | 
11 11 | foo['bar'] in obj.keys()  # SIM118
12 12 | 

SIM118.py:11:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
 9 | foo["bar"] not in obj.keys()  # SIM118
10 | 
11 | foo['bar'] in obj.keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
12 | 
13 | foo['bar'] not in obj.keys()  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
8  8  | 
9  9  | foo["bar"] not in obj.keys()  # SIM118
10 10 | 
11    |-foo['bar'] in obj.keys()  # SIM118
   11 |+foo['bar'] in obj  # SIM118
12 12 | 
13 13 | foo['bar'] not in obj.keys()  # SIM118
14 14 | 

SIM118.py:13:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
   |
11 | foo['bar'] in obj.keys()  # SIM118
12 | 
13 | foo['bar'] not in obj.keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
14 | 
15 | foo() in obj.keys()  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
10 10 | 
11 11 | foo['bar'] in obj.keys()  # SIM118
12 12 | 
13    |-foo['bar'] not in obj.keys()  # SIM118
   13 |+foo['bar'] not in obj  # SIM118
14 14 | 
15 15 | foo() in obj.keys()  # SIM118
16 16 | 

SIM118.py:15:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
13 | foo['bar'] not in obj.keys()  # SIM118
14 | 
15 | foo() in obj.keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^ SIM118
16 | 
17 | foo() not in obj.keys()  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
12 12 | 
13 13 | foo['bar'] not in obj.keys()  # SIM118
14 14 | 
15    |-foo() in obj.keys()  # SIM118
   15 |+foo() in obj  # SIM118
16 16 | 
17 17 | foo() not in obj.keys()  # SIM118
18 18 | 

SIM118.py:17:1: SIM118 [*] Use `key not in dict` instead of `key not in dict.keys()`
   |
15 | foo() in obj.keys()  # SIM118
16 | 
17 | foo() not in obj.keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^ SIM118
18 | 
19 | for key in obj.keys():  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
14 14 | 
15 15 | foo() in obj.keys()  # SIM118
16 16 | 
17    |-foo() not in obj.keys()  # SIM118
   17 |+foo() not in obj  # SIM118
18 18 | 
19 19 | for key in obj.keys():  # SIM118
20 20 |     pass

SIM118.py:19:5: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
17 | foo() not in obj.keys()  # SIM118
18 | 
19 | for key in obj.keys():  # SIM118
   |     ^^^^^^^^^^^^^^^^^ SIM118
20 |     pass
   |
   = help: Remove `.keys()`

ℹ Safe fix
16 16 | 
17 17 | foo() not in obj.keys()  # SIM118
18 18 | 
19    |-for key in obj.keys():  # SIM118
   19 |+for key in obj:  # SIM118
20 20 |     pass
21 21 | 
22 22 | for key in list(obj.keys()):

SIM118.py:26:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
24 |         del obj[key]
25 | 
26 | [k for k in obj.keys()]  # SIM118
   |        ^^^^^^^^^^^^^^^ SIM118
27 | 
28 | {k for k in obj.keys()}  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
23 23 |     if some_property(key):
24 24 |         del obj[key]
25 25 | 
26    |-[k for k in obj.keys()]  # SIM118
   26 |+[k for k in obj]  # SIM118
27 27 | 
28 28 | {k for k in obj.keys()}  # SIM118
29 29 | 

SIM118.py:28:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
26 | [k for k in obj.keys()]  # SIM118
27 | 
28 | {k for k in obj.keys()}  # SIM118
   |        ^^^^^^^^^^^^^^^ SIM118
29 | 
30 | {k: k for k in obj.keys()}  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
25 25 | 
26 26 | [k for k in obj.keys()]  # SIM118
27 27 | 
28    |-{k for k in obj.keys()}  # SIM118
   28 |+{k for k in obj}  # SIM118
29 29 | 
30 30 | {k: k for k in obj.keys()}  # SIM118
31 31 | 

SIM118.py:30:11: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
28 | {k for k in obj.keys()}  # SIM118
29 | 
30 | {k: k for k in obj.keys()}  # SIM118
   |           ^^^^^^^^^^^^^^^ SIM118
31 | 
32 | (k for k in obj.keys())  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
27 27 | 
28 28 | {k for k in obj.keys()}  # SIM118
29 29 | 
30    |-{k: k for k in obj.keys()}  # SIM118
   30 |+{k: k for k in obj}  # SIM118
31 31 | 
32 32 | (k for k in obj.keys())  # SIM118
33 33 | 

SIM118.py:32:8: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
30 | {k: k for k in obj.keys()}  # SIM118
31 | 
32 | (k for k in obj.keys())  # SIM118
   |        ^^^^^^^^^^^^^^^ SIM118
33 | 
34 | key in (obj or {}).keys()  # SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
29 29 | 
30 30 | {k: k for k in obj.keys()}  # SIM118
31 31 | 
32    |-(k for k in obj.keys())  # SIM118
   32 |+(k for k in obj)  # SIM118
33 33 | 
34 34 | key in (obj or {}).keys()  # SIM118
35 35 | 

SIM118.py:34:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
32 | (k for k in obj.keys())  # SIM118
33 | 
34 | key in (obj or {}).keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
35 | 
36 | (key) in (obj or {}).keys()  # SIM118
   |
   = help: Remove `.keys()`

ℹ Unsafe fix
31 31 | 
32 32 | (k for k in obj.keys())  # SIM118
33 33 | 
34    |-key in (obj or {}).keys()  # SIM118
   34 |+key in (obj or {})  # SIM118
35 35 | 
36 36 | (key) in (obj or {}).keys()  # SIM118
37 37 | 

SIM118.py:36:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
34 | key in (obj or {}).keys()  # SIM118
35 | 
36 | (key) in (obj or {}).keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118
37 | 
38 | from typing import KeysView
   |
   = help: Remove `.keys()`

ℹ Unsafe fix
33 33 | 
34 34 | key in (obj or {}).keys()  # SIM118
35 35 | 
36    |-(key) in (obj or {}).keys()  # SIM118
   36 |+(key) in (obj or {})  # SIM118
37 37 | 
38 38 | from typing import KeysView
39 39 | 

SIM118.py:50:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
50 | key in obj.keys()and foo
   | ^^^^^^^^^^^^^^^^^ SIM118
51 | (key in obj.keys())and foo
52 | key in (obj.keys())and foo
   |
   = help: Remove `.keys()`

ℹ Safe fix
47 47 | 
48 48 | 
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
50    |-key in obj.keys()and foo
   50 |+key in obj and foo
51 51 | (key in obj.keys())and foo
52 52 | key in (obj.keys())and foo
53 53 | 

SIM118.py:51:2: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
50 | key in obj.keys()and foo
51 | (key in obj.keys())and foo
   |  ^^^^^^^^^^^^^^^^^ SIM118
52 | key in (obj.keys())and foo
   |
   = help: Remove `.keys()`

ℹ Safe fix
48 48 | 
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
50 50 | key in obj.keys()and foo
51    |-(key in obj.keys())and foo
   51 |+(key in obj)and foo
52 52 | key in (obj.keys())and foo
53 53 | 
54 54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200

SIM118.py:52:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
50 | key in obj.keys()and foo
51 | (key in obj.keys())and foo
52 | key in (obj.keys())and foo
   | ^^^^^^^^^^^^^^^^^^^ SIM118
53 | 
54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200
   |
   = help: Remove `.keys()`

ℹ Safe fix
49 49 | # Regression test for: https://github.com/astral-sh/ruff/issues/7124
50 50 | key in obj.keys()and foo
51 51 | (key in obj.keys())and foo
52    |-key in (obj.keys())and foo
   52 |+key in (obj)and foo
53 53 | 
54 54 | # Regression test for: https://github.com/astral-sh/ruff/issues/7200
55 55 | for key in (

SIM118.py:55:5: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
54 |   # Regression test for: https://github.com/astral-sh/ruff/issues/7200
55 |   for key in (
   |  _____^
56 | |     self.experiment.surveys[0]
57 | |         .stations[0]
58 | |         .keys()
59 | | ):
   | |_^ SIM118
60 |       continue
   |
   = help: Remove `.keys()`

ℹ Unsafe fix
55 55 | for key in (
56 56 |     self.experiment.surveys[0]
57 57 |         .stations[0]
58    |-        .keys()
   58 |+        
59 59 | ):
60 60 |     continue
61 61 | 

SIM118.py:65:1: SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
   |
64 | d = SneakyDict()
65 | key in d.keys()  # SIM118
   | ^^^^^^^^^^^^^^^ SIM118
   |
   = help: Remove `.keys()`

ℹ Safe fix
62 62 | from builtins import dict as SneakyDict
63 63 | 
64 64 | d = SneakyDict()
65    |-key in d.keys()  # SIM118
   65 |+key in d  # SIM118
