This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add pattern to simplify `in dict.keys()` to `in dict` * Rephrase title
- Loading branch information
1 parent
fc69b5d
commit 9ced695
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
``` |