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

[optional ext] Emit redefined-loop-name for redefinitions of loop variables in body #5649

Merged
merged 38 commits into from
May 2, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Jan 8, 2022

Type of Changes

Type
✨ New feature

Description

Closes #5072 -- Adds new message in optional extension
Closes #5608 -- Uncouples the nested loop redefinition case from redefined-outer-name so the check can be enabled/disabled appropriately

# 1
for y in iterable:
    for y in iterable:  # [already emitted redefined-outer-name, now emits redefined-loop-name]
        ...

# 2
for y in iterable:
    y = y.lower()  # [with this PR emits redefined-loop-name]

Ultimately I'm open to the idea of making this into a new message, but then we should get a decision on whether to bring example 1 into the new message also. done!

@coveralls
Copy link

coveralls commented Jan 8, 2022

Pull Request Test Coverage Report for Build 2255071021

  • 47 of 47 (100.0%) changed or added relevant lines in 3 files are covered.
  • 116 unchanged lines in 11 files lost coverage.
  • Overall coverage increased (+0.04%) to 95.162%

Files with Coverage Reduction New Missed Lines %
pylint/testutils/checker_test_case.py 1 97.96%
pylint/testutils/pyreverse.py 1 97.92%
pylint/checkers/classes/special_methods_checker.py 2 94.83%
pylint/config/arguments_manager.py 2 98.13%
pylint/reporters/base_reporter.py 2 92.11%
pylint/checkers/utils.py 8 95.78%
pylint/reporters/text.py 9 85.61%
pylint/testutils/lint_module_test.py 10 86.67%
pylint/checkers/variables.py 23 96.61%
pylint/lint/pylinter.py 26 94.92%
Totals Coverage Status
Change from base Build 2235025626: 0.04%
Covered Lines: 15814
Relevant Lines: 16618

💛 - Coveralls

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.

I'm not very clear on the best way between extending redefined outer name and creating a new checker. We could create a new message without creating a new checker too. I hope for a consensus to be reached in the discussion.

.copyrite_aliases Outdated Show resolved Hide resolved
@jacobtylerwalls jacobtylerwalls changed the title Fix #5608: Emit redefined-outer-name for redefinitions of loop variables in body Emit redefined-outer-name for redefinitions of loop variables in body Mar 25, 2022
pylint/checkers/variables.py Outdated Show resolved Hide resolved
tests/functional/r/redefined/redefined_loop_name.py Outdated Show resolved Hide resolved
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.

Look pretty good already !

pylint/checkers/variables.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
tests/functional/r/redefined/redefined_loop_name.py Outdated Show resolved Hide resolved
@DanielNoord
Copy link
Collaborator

@jacobtylerwalls We might need to take a look at the failing pylint run here.

@Pierre-Sassoulas
Copy link
Member

Outch, if we have that much new warning ourselves I guess it's going to surprise users too. I'm more inclined to create a new optional checker now.

@jacobtylerwalls
Copy link
Member Author

Yes, I'm inclined toward that also, but I really do think we need to ask whether #1 from the top of the thread should become part of the new checker then.

Also change message type for inner loops overwriting the outer loop variable from `redefined-outer-name` to `redefined-loop-name`
@jacobtylerwalls jacobtylerwalls changed the title Emit redefined-outer-name for redefinitions of loop variables in body Emit redefined-loop-name for redefinitions of loop variables in body Mar 30, 2022
@jacobtylerwalls
Copy link
Member Author

@superbobry do you have thoughts on this approach? This would allow you to disable redefined-loop-name and also be disabling the nested loop case, uncoupling it from redefined-outer-name.

Also, do you have thoughts on making this optional or default? I will probably disable this in my own projects.

@jacobtylerwalls
Copy link
Member Author

Updated to make this an optional extension.

@jacobtylerwalls
Copy link
Member Author

Failing docs check is not relevant, see #6470

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

As I said, I really like the test. Sorry for letting this sit so long, that causes a number of change-requests due to my own aggressive deprecation PRs related to argparse and mypy 😅 Sorry about that!

pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
pylint/extensions/redefined_loop_name.py Show resolved Hide resolved
tests/functional/r/redefined/redefined_loop_name.txt Outdated Show resolved Hide resolved
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.

I like the creation of a new checker from the VariableChecker. Some checks definitely need to be disentangled to make maintenance easier.

pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
pylint/extensions/redefined_loop_name.py Outdated Show resolved Hide resolved
Co-authored-by: Daniël van Noord <[email protected]>
doc/data/messages/r/redefined-loop-name/bad.py Outdated Show resolved Hide resolved
doc/data/messages/r/redefined-loop-name/good.py Outdated Show resolved Hide resolved
pylint/checkers/utils.py Show resolved Hide resolved
pylint/checkers/variables.py Show resolved Hide resolved
jacobtylerwalls and others added 2 commits May 1, 2022 16:00
Co-authored-by: Pierre Sassoulas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

redefined-outer-name emitted for variables in the same namespace New check: mutated loop variable
4 participants