Make SIM118 fix as safe when the expression is a known dictionary #8525
Merged
charliermarsh merged 1 commit intomainfrom Nov 6, 2023
Merged
Make SIM118 fix as safe when the expression is a known dictionary #8525charliermarsh merged 1 commit intomainfrom
SIM118 fix as safe when the expression is a known dictionary #8525charliermarsh merged 1 commit intomainfrom
Conversation
fbd13cb to
96abd6f
Compare
zanieb
reviewed
Nov 6, 2023
| /// ## References | ||
| /// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) | ||
| /// | ||
| /// [preview]: https://docs.astral.sh/ruff/preview/ |
zanieb
approved these changes
Nov 6, 2023
96abd6f to
5d3127d
Compare
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM118 | 380 | 0 | 0 | 380 | 0 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Given
key in obj.keys(),objcould be a dictionary, or it could be another type that definesa
.keys()method. In the latter case, removing the.keys()attributecould lead to a runtime error.
Previously, we marked all
SIM118fixes as unsafe for this reason; however, in preview, we now mark them as safe if we caninfer that the expression is a dictionary.
Test Plan
Added a preview fixture.