-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[flake8-simplify] Apply SIM113 when index variable is of type int
#21395
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
Conversation
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| SIM113 | 3 | 3 | 0 | 0 | 0 |
ntBre
left a comment
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.
Thank you!
Would you mind making this a preview change? It seems to be in the spirit of the rule and also matches the upstream linter for this test case, but I see there are some ecosystem hits.
Preview will also be nice in case we want to iterate further by inferring the type of the argument, for example with is_int. I think ResolvedPythonType only handles literals and simple operations on them like 1 + 2 rather than using type annotations. (I'm not saying we need to or should do that, just an idea)
|
SIM113’s recommendation is only safe when the index variable’s initial value is a strict instance of |
|
Ah, thanks for the clarification! Disregard my last paragraph then, but I'd still lean toward making it a preview change. |
|
Thanks for the feedback! I updated the rule to be gated behind preview for strict instances of |
ntBre
left a comment
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.
Thank you!
crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs
Outdated
Show resolved
Hide resolved
flake8-simplify] Apply SIM113 when index variable is type intflake8-simplify] Apply SIM113 when index variable is of type int
Summary
Fixes #21393
Now the rule checks if the index variable is initialized as an
inttype rather than only flagging if the index variable is initialized to0. I usedResolvedPythonTypeto check if the index variable is aninttype.Test Plan
Updated snapshot test for
SIM113.