-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
SIM118
fix as safe when the expression is a known dictionary (#…
…8525) ## Summary Given `key in obj.keys()`, `obj` _could_ be a dictionary, or it could be another type that defines a `.keys()` method. In the latter case, removing the `.keys()` attribute could lead to a runtime error. Previously, we marked all `SIM118` fixes as unsafe for this reason; however, in preview, we now mark them as safe if we can infer that the expression is a dictionary. ## Test Plan Added a preview fixture.
- Loading branch information
1 parent
c07947b
commit 3730137
Showing
5 changed files
with
661 additions
and
215 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM118.py
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
obj = {} | ||
|
||
key in obj.keys() # SIM118 | ||
|
||
key not in obj.keys() # SIM118 | ||
|
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
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
Oops, something went wrong.