Skip to content
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

Merged
merged 2 commits into from Jul 7, 2021

Conversation

yushao2
Copy link
Collaborator

@yushao2 yushao2 commented Jul 3, 2021

Steps

  • Add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

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

Type
🐛 Bug fix

Related Issue

Closes #4664

@yushao2 yushao2 added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 3, 2021
@yushao2 yushao2 added this to the 2.9.4 milestone Jul 3, 2021
@coveralls
Copy link

coveralls commented Jul 3, 2021

Coverage Status

Coverage decreased (-0.01%) to 92.038% when pulling 9706392 on yushao2:fix-use-maxsplit-arg into e4cd2ef on PyCQA:main.

Copy link
Member

@cdce8p cdce8p left a 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)):
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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 :)

@yushao2 yushao2 merged commit 708527d into pylint-dev:main Jul 7, 2021
@yushao2 yushao2 deleted the fix-use-maxsplit-arg branch July 7, 2021 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use-maxsplit-arg false positive when index is incremented inside a loop
4 participants