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

Commit

Permalink
Replace in dict.keys() with in dict (#19)
Browse files Browse the repository at this point in the history
* Add pattern to simplify `in dict.keys()` to `in dict`

* Rephrase title
  • Loading branch information
vlopezferrando authored Sep 19, 2023
1 parent fc69b5d commit 9ced695
Showing 1 changed file with 48 additions and 0 deletions.
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()
```

0 comments on commit 9ced695

Please sign in to comment.