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

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

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

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

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

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

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

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

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

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

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

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

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

SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
  --> SIM118.py:34:1
   |
32 | (k for k in obj.keys())  # SIM118
33 |
34 | key in (obj or {}).keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
35 |
36 | (key) in (obj or {}).keys()  # SIM118
   |
help: Remove `.keys()`
   |
33 |
   - key in (obj or {}).keys()  # SIM118
34 + key in (obj or {})  # SIM118
35 |
   |
note: This is an unsafe fix and may change runtime behavior

SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
  --> SIM118.py:36:1
   |
34 | key in (obj or {}).keys()  # SIM118
35 |
36 | (key) in (obj or {}).keys()  # SIM118
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
37 |
38 | from typing import KeysView
   |
help: Remove `.keys()`
   |
35 |
   - (key) in (obj or {}).keys()  # SIM118
36 + (key) in (obj or {})  # SIM118
37 |
   |
note: This is an unsafe fix and may change runtime behavior

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

SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
  --> SIM118.py:51:2
   |
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
   |  ^^^^^^^^^^^^^^^^^
52 | key in (obj.keys())and foo
   |
help: Remove `.keys()`
   |
50 | key in obj.keys()and foo
   - (key in obj.keys())and foo
51 + (key in obj)and foo
52 | key in (obj.keys())and foo
   |

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

SIM118 [*] Use `key in dict` instead of `key in dict.keys()`
  --> SIM118.py:55:5
   |
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 | | ):
   | |_^
60 |       continue
   |
help: Remove `.keys()`
   |
57 |         .stations[0]
   -         .keys()
58 +         
59 | ):
   |
note: This is an unsafe fix and may change runtime behavior

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