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 negative for used-before-assignment when some except handlers don't define a name #5764

Merged
merged 22 commits into from
Feb 10, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Feb 2, 2022

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Fixes #5524.

In discussion I suggested closing #2835 as a duplicate, but if folks like we could "unlink" the two and reopen the older ticket.

The older ticket is just suggesting "always assume try statements fail", and @cdce8p suggested a new message for that (possibly-unbound). Probably a 2.14 or later thing. By contrast this PR is just fixing a quick false negative. Sorry for not seeing that we were more likely to tackle these separately! Edit: done!

@coveralls
Copy link

coveralls commented Feb 2, 2022

Pull Request Test Coverage Report for Build 1815244914

  • 31 of 31 (100.0%) changed or added relevant lines in 1 file are covered.
  • 41 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.04%) to 93.961%

Files with Coverage Reduction New Missed Lines %
pylint/utils/linterstats.py 5 96.36%
pylint/checkers/utils.py 6 96.07%
pylint/lint/pylinter.py 30 94.6%
Totals Coverage Status
Change from base Build 1784689763: 0.04%
Covered Lines: 14890
Relevant Lines: 15847

πŸ’› - Coveralls

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Feb 2, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Negative πŸ¦‹ No message is emitted but something is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check labels Feb 2, 2022
Copy link
Contributor

@areveny areveny left a comment

Choose a reason for hiding this comment

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

Great! Thanks for the changes and really nice simplification with the last commit.

I'm satisfied with this, if we could get a second approval I think this is ready to merge. Thanks!

@DanielNoord DanielNoord self-requested a review February 5, 2022 20:54
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.

Small changes, but this looks great!

@jacobtylerwalls just to get this right, what do you propose in terms of issue management. What should be opened/closed after this has been merged?

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.

One final question!

pylint/checkers/variables.py Outdated Show resolved Hide resolved
@jacobtylerwalls
Copy link
Member Author

@areveny @DanielNoord thanks for the reviews and bugspotting. I'm glad we're getting a real v1.0 of control flow for try/except into something that should just work!

in terms of issue management

Let's pretend I never called the two issues duplicates! Specifically:

And then I can adjust this PR to say "closes" instead of "partially closes" #5524. Sorry for the extra work, but now I see from discussion we're likely to address the bigger-picture issue with a new message, so better to keep it all separate.

@DanielNoord
Copy link
Collaborator

I have opened and made the comments as you suggested. I'm going to ask for a review from Pierre as this is quite a large PR again.

Just FYI: I think this should be the last new PR to go into 2.13. We really (really really really) need to release as we're hitting almost 300 issues/PRs closed with a lot of useful features as well. The release is also blocking some important maintenance work such as the argparse refactor.
Any help with any of the open 2.13 issues would be much appreciated. Especially with #5645 as I don't have the necessary hardware to work on it myself...

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, the tests are really nice, and this will be a nice addition to 2.13. Also thank you for providing early feedback @areveny, :)

Small question, I noticed that there could be more tests if we do the permutation for "defined in one handler only" with unpacked iterable, or chained assignment. I suppose it's because it's not necessary to check this again as it's already checked in funcok_4 and func_ok5, and not doing all permutation would speed the functional tests up ?

and other_node_statement.parent.parent.parent.parent_of(
node_statement
)
and closest_try_except.parent.parent_of(node_statement)
Copy link
Member

Choose a reason for hiding this comment

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

Good job generalizing here, this is a lot cleaner.

@jacobtylerwalls
Copy link
Member Author

I went ahead and added the tests. After all, just a few comments above I was very keen to tell the world that true positives and true negatives might hit different code paths! πŸ˜„

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative πŸ¦‹ No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False-negative used-before-assignment after try-except block
5 participants