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
Fix false-positive of use-maxsplit-arg
when index is incremented inside a loop
#4666
Conversation
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.
Looks good! Added a 2-3 small notes. Feel free to merge it once addressed.
if isinstance(node.parent.slice, astroid.Name): | ||
# Check if loop present within the scope of the node | ||
scope = node.scope() | ||
for loop_node in scope.nodes_of_class((astroid.For, astroid.While)): |
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.
Could you add type hints for loop_node
and assignment_node
below (with typing.cast
).
I should probably add types to NodeNG.nodes_of_class
soon, so we don't need to anymore.
source = 'A.B.C.D.E.F.G' | ||
other_iterable = range(5) | ||
i = 0 | ||
for j in other_iterable: |
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.
for j in other_iterable: | |
for j in range(5): |
I would simplify it a bit
use-maxsplit-arg:82:4::Use '1,2,3'.split('\n', maxsplit=1)[0] instead | ||
use-maxsplit-arg:83:4::Use '1,2,3'.rsplit('split', maxsplit=1)[-1] instead | ||
use-maxsplit-arg:84:4::Use '1,2,3'.split('rsplit', maxsplit=1)[0] instead | ||
use-maxsplit-arg:5:12::Use '1,2,3'.split(',', maxsplit=1)[0] instead:HIGH |
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.
Just my opinion, but I'm not a big fan of adding :HIGH
and creating larger diffs than necessary. That makes it quite difficult to review.
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.
LGTM 😄 Only small thing is that the refactor could have been done in another MR first so the real changes are easier to review :)
6cc9b52
to
9706392
Compare
Steps
Description
Handle case where variable subscripts are mutated within a loop, see #4664
Minor refactoring to if/else logic as there were linting issues where there's too much if/else nesting
Type of Changes
Related Issue
Closes #4664