-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make SIM118
fix as safe when the expression is a known dictionary
#8525
Conversation
fbd13cb
to
96abd6f
Compare
/// ## References | ||
/// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) | ||
/// | ||
/// [preview]: https://docs.astral.sh/ruff/preview/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this render?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
96abd6f
to
5d3127d
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
SIM118 | 380 | 0 | 0 | 380 | 0 |
Summary
Given
key in obj.keys()
,obj
could 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
SIM118
fixes 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.