Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Replace in dict.keys() with in dict #19

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .grit/patterns/in_dict_keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: In dict instead of in dict.keys()
---

Rewrite `in dict.keys()` to `in dict`. Rule [SIM118](https://github.com/MartinThoma/flake8-simplify/issues/40) from [flake8-simplify](https://github.com/MartinThoma/flake8-simplify).

Limitations:
- The change is not applied to for loops.


```grit
engine marzano(0.1)
language python

`$var in $dict.keys()` => `$var in $dict`
```

## Replace `in dict.keys()` with `in dict`

```python
found = key in foo.keys()

if name in names.keys():
print(f"{name} found")

# TODO: this for loop should also be simplified
for name in names.keys():
print(name)

key in sorted(foo.keys())[:10]

(a, b) in foo.items()
```

```python
found = key in foo

if name in names:
print(f"{name} found")

# TODO: this for loop should also be simplified
for name in names.keys():
print(name)

key in sorted(foo.keys())[:10]

(a, b) in foo.items()
```
Loading